Skip to content

Commit

Permalink
added show action
Browse files Browse the repository at this point in the history
  • Loading branch information
himynameisjonas committed Jan 29, 2011
1 parent c6242ef commit b1b7537
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/controllers/blog_controller.rb
Expand Up @@ -2,5 +2,9 @@ class BlogController < ApplicationController
def index
@photos = Photo.all
end


def show
@photo = Photo.find(params[:id])
end

end
13 changes: 11 additions & 2 deletions app/models/photo.rb
@@ -1,5 +1,5 @@
class Photo
attr_accessor :id, :url_thumbnail
attr_accessor :id, :thumbnail_url, :large_url
require 'open-uri'

def initialize(attributes = {})
Expand All @@ -13,8 +13,17 @@ def self.all
doc.css("photo").map do |photo|
self.new(
:id => photo.attr("id"),
:url_thumbnail => photo.attr("url_sq")
:thumbnail_url => photo.attr("url_sq"),
:large_url => photo.attr("url_l")
)
end
end

def self.find(id)
self.all.select{|photo| photo.id == id}.first
end

def to_param
self.id
end
end
4 changes: 3 additions & 1 deletion app/views/blog/index.html.erb
Expand Up @@ -3,6 +3,8 @@

<ul>
<% @photos.each do |photo| %>
<li><img src="<%= photo.url_thumbnail %>" /></li>
<li>
<%= link_to(image_tag(photo.thumbnail_url), show_path(photo)) %>
</li>
<% end %>
</ul>
1 change: 1 addition & 0 deletions app/views/blog/show.html.erb
@@ -0,0 +1 @@
<%= image_tag @photo.large_url %>
5 changes: 4 additions & 1 deletion config/routes.rb
@@ -1,6 +1,9 @@
Flickrblog::Application.routes.draw do
get "blog/index"
root :to => "blog#index"

match 'show/:id' => 'blog#show', :as => :show

# get "blog/index"

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down

0 comments on commit b1b7537

Please sign in to comment.