On 23.02.2012, at 22:23, Roger Patrick wrote:

> Now in my gamescontroller I have the following in my index:
> 
>  def index
>    @games = Game.paginate(:per_page => 4, :page =>
> params[:page]).search(params[:search])
>    @games = @games.find_by_console(params[:console]) unless
> params[:console].blank?
>  end
> 
> The problem I receive is that when I click on the Gaming section of my
> website I receive the following error message which I assume is to say
> activerecord is not connecting:
> 
> undefined method `find_by_console' for
> #<WillPaginate::Collection:0x52cb9d8>

At first, .find_by_<attr_name> is a ActiveRecord::Relation's method. That is 
why it doesn't  responded.
At second, this method is a "lazy" method, oriented to return _just_one_ 
instance, corresponding to condition. Is that your app-logic? I don't think so..

So, your way is:

games_relation = case params[:console].present?
when true then Game.where(:console => params[:console])
else Game
end
@games = games_relation.paginate(:per_page => 4, :page => 
params[:page]).search(params[:search])

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to