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 6052241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:54:25+00:00 2026-05-23T07:54:25+00:00

I want to do an advanced search form in Rails that has these abilities:

  • 0

I want to do an advanced search form in Rails that has these abilities:

Required

  • 5 field_tags where a user can input a search term that searches a specific field in the table.
  • 1 field_tag that searches all fields in the table (DONE).

Preferable

  • Be able to specify operators like AND, OR, etc. on these searches.
  • Be able to specify more detailed operators like SO does with this, inquestion, etc.

How can I make this happen in practice, especially the 1st bullet point?

  • 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-23T07:54:25+00:00Added an answer on May 23, 2026 at 7:54 am

    I haven’t tested this, someone please edit the syntax accordingly, but logically I do not see why it wouldn’t work.

    app/views/posts/_form.html.erb

    <% form_tag(@post, :method => :get) do %>
       <p>
         Search Phrase
             <%= text_field_tag :phrase, params[:phrase] %>
       </p>
       <p>
         <%= radio_button_tag :search_everything, true %>
         Search Everything
       </p>
       <p>
         <%= radio_button_tag :search_everything, false %>
         Advanced Search
       </p>
        <div id="advacned_search">
            <% format_column_names(Post.column_names) do |cn| %>
                <%= check_box_tag "post[column_names][]", cn %> Field 
                <%= check_box_tag cn %><br/>
            <% end %>
        </div>
        <p>
                <%= submit_tag "Search" %>
            </p>
    <% end %>
    

    app/helpers/post_helper.rb

        def format_column_names(cns)
            filtered_names = "id" #add the other column names you do not want
            cns.delete_if {|cn| filtered_names.include?(cn) }
            return cns
        end 
    

    app/controllers/posts_controller.rb

        def index
            phrase = params[:phrase]
            if params[:search_everything]
                @posts = Post.find(:all, :conditions => everything_conditions(phrase))
            else
                column_names = params[:column_names]
                @posts = Post.find(:all, :conditions => specific_conditions(column_names, phrase))
            end
        end 
    
        def everything_conditions(phrase)
            [Post.column_names.map {|cn| "#{cn}=?" }, phrase]
        end
    
        def specific_conditions(phrase, column_names)
            [column_names.map {|cn| "#{cn}=?" }.join("or "), phrase]
        end 
    

    public/javascripts/post.js#make sure you include jQuery and this file into your view`

    jQuery.noConflict();
    jQuery(document).ready(function() { 
    
        $("input[name$='search_everything']").click(function(){
            var value = $(this).val();
            if(value) {
              $("#advanced_search").hide();
            } else {
              $("#advanced_search").show();
            }
         }
    
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Magento 1.5.0.1 and I want to move my advanced search form to
I want to change the advanced search layout to my needs. Instead of select
i have a form that have a field which hold query for search and
I've built a modified search form on top of Magento's advanced search module. I've
I have a search form that searches a table in my database. The table
I have a search form: <form id=global_search> <input id=global_search_input name=search_query placeholder=Enter search text> <input
I have a form where users can search all the entries in a table
hi i have search form and when i search item in database i want
I am trying to create search form when user search for a course it
I have page with a simple table and advanced search form. I pass List<Customers>

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.