Skip to content
Browse files

added show action

  • Loading branch information...
1 parent c6242ef commit b1b7537a6cf1ecb79300ddf113db8457e3470456 @himynameisjonas himynameisjonas committed Jan 29, 2011
Showing with 24 additions and 5 deletions.
  1. +5 −1 app/controllers/blog_controller.rb
  2. +11 −2 app/models/photo.rb
  3. +3 −1 app/views/blog/index.html.erb
  4. +1 −0 app/views/blog/show.html.erb
  5. +4 −1 config/routes.rb
View
6 app/controllers/blog_controller.rb
@@ -2,5 +2,9 @@ class BlogController < ApplicationController
def index
@photos = Photo.all
end
-
+
+ def show
+ @photo = Photo.find(params[:id])
+ end
+
end
View
13 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 = {})
@@ -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
View
4 app/views/blog/index.html.erb
@@ -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>
View
1 app/views/blog/show.html.erb
@@ -0,0 +1 @@
+<%= image_tag @photo.large_url %>
View
5 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.

0 comments on commit b1b7537

Please sign in to comment.
Something went wrong with that request. Please try again.