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

My link_to tag is: <%= link_to(My test title,{:controller=>search, :action=>for-sale, :id=> listing.id, :title => listing.title,
I want to use link_to to create a new article and set the article's
My link_to and url_for etc. methods are generating paths in the pattern of :controller/:id/:action,
I want to embed a link to a controller action in my page so
I want to create link_to google like in Rails. Let me explain. On simple
Trying to link to an object name with <%= link_to '<%= museum.name %>', museum
I want to use link_to wrap some HTML,but I meet some problem. <%= link_to
link_to causes the json response to be downloaded to my machine which I dont
How to add a hash parameter in link_to. I need to generate a URL
Hello how can i link to a SonataUserAdmin Controller Page ie. list in a

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.