You are not logged in.

#1 2006-04-27 20:25:17

viniosity
Member
From: New York, NY
Registered: 2005-01-22
Posts: 404
Website

Searching in Ruby on Rails

I'm trying to create a way to search in my Ruby on Rails program.  I am using the FullTextSearch plugin which seems to be working ok.  The problem I am having is passing the info from the view to the controller.

My controller (post_controller.rb), again based on FullTextSearch, is simply:

 def search
        @results = Product.search query
 end

My view is a bit more complicated:

<table>
  <div class="search"  <%= form_tag :action =>'search', :controller => 'post' %>

<td width="50" <%= text_field 'product','query' %>
<td width="100"><%= submit_tag "Search" %>
                
<%= end_form_tag %>
  </div>
</table>
..snip

Then there is some code to display the results.  Currently it just displays everything because query is not being passed along to my controller. If I replace my controller search method with @results = Product.search "milk" my view dutifully displays all products that contain milk so I know that part works.

Am I making another stupid mistake here?  Else is there any easier way to implement search?

Offline

#2 2006-05-07 07:21:31

mindtriggerz
Member
Registered: 2004-07-06
Posts: 31

Re: Searching in Ruby on Rails

I do believe that should be @query in the controller...
But it's been awhile for me and Rails, so I can't tell you for sure.


[img]http://www.d-destroy.de/userbars/windowsserver.png[/img]
[Pry Developer][FlashHater]

Offline

#3 2006-05-11 15:05:03

viniosity
Member
From: New York, NY
Registered: 2005-01-22
Posts: 404
Website

Re: Searching in Ruby on Rails

mindtriggerz wrote:

I do believe that should be @query in the controller...
But it's been awhile for me and Rails, so I can't tell you for sure.

Actually I just had to change the controller to this:

def search
  @results = Product.search params[:product][:title]
end

and it worked!  Ruby is soo confusing sometimes..

Offline

Board footer

Powered by FluxBB