I am using a nested search resource in my Rails 3 Application where I am following Ryan Bates Railscast on Advanced Searching. The problem Arises however when I call Will_Paginate on my Search Model because obviously it requires a page parameter to be passed into it. I Grab the page parameter in my Search con开发者_运维知识库troller, but how Can I inject this into my model for will_paginate to work Properly?? (I need to inject it into my model as this is where the database query is run for parameters passed in)
For anyone who thinks this has already been answered, I do apologise and have not seen a relevent question Myself!
Thanks.
in your model:
def search(to_search, page)
unless to_search.blank?
where("field = ?",to_search).paginate(:per_page =>20, :page=> page)
else
paginate(:per_page =>20, :page=> page)
end
end
in your controller
@things = Thing.search(params[:search],params[:page])
you mention nested model in your title but not in the OP but the logic is the same just pass it as a parameter to a function.
精彩评论