来自Rails form_for的params hash的自定义名称 [英] Custom name for params hash from Rails form_for

查看:57
本文介绍了来自Rails form_for的params hash的自定义名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,使用form_for(@foo)表示在表单操作的后端,您将在params[:foo]中保存表单数据,但就我而言,我想将自定义名称空间应用于这些参数,即params[:bar],而不是params[:foo].

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].

我不是在说要通过向form_for方法提供:namespace参数来延长名称空间.相反,我的当前名称过长,我想将其缩写.更重要的是,我实际上是在交换新模型来代替现有模型,因此控制器填充了对params[:quoter]的调用,而我们的新模型提供了params[:company_quoter_intf_quoter].有什么想法吗?

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?

规格:Ruby 1.9.3,Rails 3.2.3

推荐答案

您正在寻找的是:

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

有关此文档的信息,请访问:

The documentation for this can be found at:

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

这篇关于来自Rails form_for的params hash的自定义名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆