Form_for search question

Hi there,

I’m going through this tutorial on Thinking Sphinx:

I’m really new to searches in rails; how do I get the search results to
display on a separate search result page?

I have a search form that appears on every page (in my
application.html.erb template) that looks like this:

<% form_for :recipes, :url => {:controller => “pages”, :action =>
“searchresults”} do |f| %>
<%= f.text_field :search %>
<%= submit_tag “Search” %>
<% end %>

This is a recipe search, but it doesn’t even work because :search isn’t
a field in the recipes table. I just want to grab a params[:search] that
I can use in my controller.

Here’s what my pages_controller.rb looks like:

def searchresults
@recipes = Recipe.search params[:search], :page => params[:page],
:per_page => 10, :field_weights => {:title => 20}, :match_mode =>
:boolean
end

I have no problem with this code; I have a searchresults.html.erb that
matches up just fine. But params[:search] == nil, so that’s no good. :frowning:

How should I construct my form?

Thanks!

On Sep 14, 9:34 pm, Dave A. [email protected]
wrote:

I have no problem with this code; I have a searchresults.html.erb that
matches up just fine. But params[:search] == nil, so that’s no good. :frowning:

Check params again. you search is there, just not where you think
(hint: if you put <%= debug params %> in the view, that will dump all
the params to the screen. alternatively just look in development.log.

Fred

Frederick C. wrote:

On Sep 14, 9:34�pm, Dave A. [email protected]
wrote:

I have no problem with this code; I have a searchresults.html.erb that
matches up just fine. But params[:search] == nil, so that’s no good. :frowning:

Check params again. you search is there, just not where you think
(hint: if you put <%= debug params %> in the view, that will dump all
the params to the screen. alternatively just look in development.log.

Fred

Thanks! I switched to a form_tag because I wasn’t querying the model.
Here’s what I came up with:

<% form_tag :action => ‘searchresults’ do %>
<%= text_field_tag :search %>
<%= submit_tag “Search” %>
<% end %>