Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
V and C for multiple queries in one page
2 Posts
V and C for multiple queries in one page

I have three tables grandparents has_many * parents has_many children. And a table that is not directly related to any of these called professions*.

How do I create a view where the user is provided with query boxes for searching all of these tables. How can different query boxes be linked together? For ex. how do I find a name "someone" in 'grandparents' who has a link to "somebody" in 'parents and has a profession "doctor".

Could you please elaborate how we can do this using autocomplete. Could you please illustrate by including both the controller and view code? Thanks from a newbie!

I will try to give an outline of how it can be done , please edit this according to your requirement

in your view have a text field where users will be searching for a name.


                                        :size => 40
                                        :controller           => '/grandparents',
                                        :frequency            => 0.5,                                           
                                        :min_chars            => 2
                                     ) %>

In your controller your have to write a method that will capture the text typed and will query the database for a match.

def auto_complete_for_grandparents_name
  search = params[xxxxx]  # get the name typed in the text field
  @matches= GrandParent.find_by_sql("SELECT  id, name FROM grand_parents WHERE (name LIKE '%#{search.sql_safe}%')")     

You can use the render :inline property to display the result set in your view .

Forum Rating: 100
Sign In To Rate Post
2 Posts
Login to add your message