Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: Using a POST form on the index page?

In my Rails 3.0 app I have a series of very large search forms on my resource:index page, requiring the use of POST instead of GET.

Currently, the app is routing the POST request to resource#create, when I want it to route to resource#index. I realize this is the RESTful route, but need to override it. How can I do that, while also preserving the ability to create a new record of that resource?

Thanks much.

like image 796
Andrew Avatar asked May 16 '11 00:05

Andrew


1 Answers

You're better off having a "search" action that is post-only - and then renders the index template eg:

class MyController < ...
  def search
     @my_things = MyThing.find_with_search_params(params[:search]) 
     render :action => :index
  end
end
like image 181
Taryn East Avatar answered Oct 11 '22 16:10

Taryn East