views:

463

answers:

2

I am attempting to use form_for to implement a search form that works with a table-less Search model I created. The search form keeps triggering the 'index' action. I assume I should use 'new' to create the form and 'create' the process the search query. Looking at the log, my POST is getting changed into a GET. Here's my code:

/searches/new.html.erb:

<% form_for :searches, @search, :url => searches_path, :html => {:method => :post} do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :keywords %><br />
    <%= f.text_field :keywords %>
  </p>
  <p><%= f.submit "Submit" %></p>
<% end %>

What's the standard way for triggering the 'create' action with form_for?

A: 

Are you using the RESTful map.resources :searches ?
If so, shouldn't your :url be set to new_search_path ?

andi
Yes, I'm using map.resources :searches.pural_path plus POST should map to 'create.' new_singular_path would map to new which I'm using to display the form. I'd like the form at /searches/new to be processed with 'create' but I keep getting /index instead.
thaiyoshi
+1  A: 

form_for is used with models. For a simple search form, I reccommend doing something like this:

<% form_tag posts_path, :method => :get do |f| %>
  <%= f.text_field :query %>
<% end %>

You'll get /posts?query=wtf.

August Lilleaas