From 993df4a472524b89e4766b8fe9eac7175b23d588 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Sun, 25 Sep 2011 15:20:14 +0800 Subject: [PATCH] better tag handling. give 404 for non existing ones. link to tag.title for non-ascii chars --- app/controllers/photos_controller.rb | 9 ++++++--- app/controllers/tags_controller.rb | 2 +- app/views/tags/index.html.erb | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index a9f0ccb..909d157 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -4,11 +4,14 @@ class PhotosController < ApplicationController def index if params[:tag_id] && params[:album_id] - @photos = Tag.find_by_title( params[:tag_id] ).photos.find(:all, :conditions => ['photos.album_id = :album', {:album => Album.find(params[:album_id] ) } ], :order => "photos.id ASC") + @tag = Tag.find_by_title!( params[:tag_id] ) + @photos = @tag.photos.find(:all, :conditions => ['photos.album_id = :album', {:album => Album.find(params[:album_id] ) } ], :order => "photos.id ASC") elsif params[:tag_id] - @photos = Tag.find_by_title( params[:tag_id] ).photos.find(:all, :order => "photos.id ASC") + @tag = Tag.find_by_title!( params[:tag_id] ) + @photos = @tag.photos.find(:all, :order => "photos.id ASC") elsif params[:album_id] - @photos = Album.find( params[:album_id]).photos.find(:all, :order => "photos.id ASC") + @album = Album.find( params[:album_id]) + @photos = @album.photos.find(:all, :order => "photos.id ASC") elsif params[:q] #search = params[:q] #search = search.split("AND").map{|q|q.strip} diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 6d8c194..391fea7 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -5,7 +5,7 @@ class TagsController < ApplicationController if params[:album_id] @tags = Album.find( params[:album_id] ).photo_tags else - @tags = Tag.find( :all, :order => 'title') + @tags = Tag.order('title') end respond_to do |format| format.html diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 9695c93..bca7cd7 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -1,4 +1,4 @@

Tags

<% for tag in @tags %> -<%= link_to h(tag.title), tag_photos_path(tag) %>  +<%= link_to tag.title, tag_photos_path(tag.title) %>  <% end %> \ No newline at end of file