link_to 'articles', articles_path, :attr1 => 'foo', :attr2 => 'bar'
And in the controller:
Article.find_all_by_attr1_and_attr2(params[:attr1], params[:attr2])
However if the controller receives only [:attr1] I get a nil.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dynamic finders may not be the right way to go if some of finders aren’t actually present. In this case, you’re probably better off using
Article.find(:all, :conditions => {})on Rails 2 andArticle.where()on Rails 3.Here’s a method I came up with for another question a while back:
In the above case, you’d loop over all fields in the array, and add each one of them to the resulting hash if it’s in and not empty in
params. Then, you pass the hash to the finder, and everything’s fine and dandy.