Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3794044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:52:09+00:00 2026-05-19T12:52:09+00:00

link_to ‘articles’, articles_path, :attr1 => ‘foo’, :attr2 => ‘bar’ And in the controller: Article.find_all_by_attr1_and_attr2(params[:attr1],

  • 0
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:52:10+00:00Added an answer on May 19, 2026 at 12:52 pm

    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 and Article.where() on Rails 3.

    Here’s a method I came up with for another question a while back:

    conditions = [:attr1, :attr2].inject({}) do |hsh, field|
      hsh[field] = params[field] if params[field] && params[field].present?
      hsh
    end
    
    # Rails 2
    @articles = Article.find(:all, :conditions => conditions)
    
    # Rails 3
    @articles = Article.where(conditions)
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to embed a link to a controller action in my page so
I want to use link_to wrap some HTML,but I meet some problem. <%= link_to
I want to link to bookmark on a page (mysite.com/mypage.htm#bookmark) AND visually highlight the
I want to link to a page which contains multiple support topics. When the
When providing a link to a PDF file on a website, is it possible
I am trying to link to a file that has the '#' character in
When you create a link to an executable file intended for download (like say
Anyone have a link to what the C++ standard says regarding a compiler removing
I want to give a link to a postscript file, but first I want
I saw a link to find out if AD was running, but am not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.