find not find by title

rails2
Espen Antonsen 2009-06-16 01:22:51 +02:00
parent 5f16fa8948
commit 0f62e5d93d
5 changed files with 10 additions and 10 deletions

View File

@ -4,7 +4,7 @@ class AlbumsController < ApplicationController
def index
if params[:tag_id]
@albums = Album.find(:all, :conditions => [ "Id IN ( SELECT DISTINCT Photos.ALbum_id FROM Photos WHERE Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags WHERE Photo_Tags.Tag_Id = :q) )", { :q => Tag.find_by_title( params[:tag_id] ).id } ])
@albums = Album.find(:all, :conditions => [ "Id IN ( SELECT DISTINCT Photos.ALbum_id FROM Photos WHERE Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags WHERE Photo_Tags.Tag_Id = :q) )", { :q => Tag.find( params[:tag_id] ).id } ])
elsif params[:q]
@albums = Album.find(:all, :conditions => [ "Id IN ( SELECT DISTINCT Photos.Album_Id FROM Photos WHERE Photos.description LIKE :q OR Photos.title LIKE :q OR Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags LEFT OUTER JOIN Tags ON Photo_Tags.Tag_Id = Tags.Id WHERE Tags.Title LIKE :q) )", { :q => '%' + params[:q] + '%' } ])
else

View File

@ -36,11 +36,11 @@ class CollectionsController < ApplicationController
end
def edit
@collection = Collection.find_by_title( params[:id])
@collection = Collection.find( params[:id])
end
def update
@collection = Collection.find_by_title( params[:id])
@collection = Collection.find( params[:id])
if @collection.update_attributes(params[:collection])
flash[:notice] = "Collection updated!"
redirect_to @collection
@ -50,7 +50,7 @@ class CollectionsController < ApplicationController
end
def destroy
@collection = Collection.find_by_title( params[:id])
@collection = Collection.find( params[:id])
if @collection.destroy
redirect_to collections_path
else

View File

@ -4,9 +4,9 @@ class PhotosController < ApplicationController
def index
if params[:tag_id]
@photos = Tag.find_by_title( params[:tag_id] ).photos.find(:all, :order => "Photos.Id ASC")
@photos = Tag.find( params[:tag_id] ).photos.find(:all, :order => "Photos.Id ASC")
elsif params[:album_id]
@photos = Album.find_by_title( params[:album_id]).photos.find(:all, :order => "Photos.Id ASC")
@photos = Album.find( params[:album_id]).photos.find(:all, :order => "Photos.Id ASC")
elsif params[:q]
@photos = Photo.find(:all, :limit => 20, :conditions => [ "Photos.description LIKE :q OR Photos.title LIKE :q OR Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags LEFT OUTER JOIN Tags ON Photo_Tags.Tag_Id = Tags.Id WHERE Tags.Title LIKE :q) ", { :q => '%' + params[:q] + '%' } ], :include => :album, :order => "Photos.Id ASC" )
else
@ -21,7 +21,7 @@ class PhotosController < ApplicationController
def untouched
if params[:album_id]
@album = Album.find_by_title( params[:album_id])
@album = Album.find( params[:album_id])
@photos = @album.photos.untouched
else
@photos = Photo.untouched()
@ -51,7 +51,7 @@ class PhotosController < ApplicationController
end
def upload
@album = Album.find_by_title( params[:album_id])
@album = Album.find( params[:album_id])
end
def create

View File

@ -13,7 +13,7 @@ end
Given /^I have albums titled (.+) in collection (.+)$/ do |titles,collection|
titles.split(', ').each do |title|
CollectionAlbum.create( :collection => Collection.find_by_title(collection), :album => Album.create!(:title => title) )
CollectionAlbum.create( :collection => Collection.find(collection), :album => Album.create!(:title => title) )
end
end

View File

@ -13,5 +13,5 @@ Then /^I should have ([0-9]+) collections?$/ do |count|
end
Then /^collection (.+) should have ([0-9]+) albums?$/ do |collection,count|
Collection.find_by_title(collection).albums.count.should == count.to_i
Collection.find(collection).albums.count.should == count.to_i
end