Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom name for params hash from Rails form_for

Ordinarily, using form_for(@foo) means that on the back end of the form's action, you'll have the form data in params[:foo], but in my case I'd like to have a custom namespace applied to these params, i.e. params[:bar], not params[:foo].

I'm not talking about making the namespace longer by supplying the :namespace argument to the form_for method. To the contrary, my current name is overlong, and I want to shorten it. More importantly, I'm actually swapping a new model in place of an existing one, so the controller is filled with calls to params[:quoter], whereas our new model supplies params[:company_quoter_intf_quoter]. Any ideas?

Specs: Ruby 1.9.3, Rails 3.2.3

like image 947
JellicleCat Avatar asked Jun 28 '12 16:06

JellicleCat


1 Answers

What you are looking for is:

form_for(@foo, :as => :bar)

The documentation for this can be found at:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

like image 146
Ylan S Avatar answered Nov 07 '22 04:11

Ylan S