You are not logged in.
Pages: 1
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
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
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
Pages: 1