内容简介:翻译自:https://stackoverflow.com/questions/5912670/additional-parameter-in-form-for-in-rails
是否可以在rails中的表单数据之外提交另一个参数?我的问题是我为不同的类渲染不同的表单并将它们发送到相同的create方法.我想发送带有表单的类(因为值不是哈希中的键).
类似于:type参数(实际上不起作用)
<%= form_for(@an_object, :url => { :controller => :a_controller, :action => :create }, :type => @an_object.class.to_s.underscore) do |f| %>
帖子消息如下:
{"commit"=>"Create Class of an Object", "authenticity_token"=>"/iqu0A8/AocDT3HyjL5/+bKZiLkyr4FE71u/mc8Wx0Y=", "utf8"=>"✓", "class_of_an_object"=>{"name"=>"a name", "description"=>"a description"}}
我会有一个“类型”=> “class_of_an_object”,但直接在散列中不在“class_of_an_object”散列中.
<%= form_for @an_object, :url => { :controller => :a_controller, :action => :create, :type => @an_object.class.to_s.underscore } do |f| %>
我更喜欢使用命名路线
<%= form_for @object, :url => object_path(@object, :type => "whtever"), :html => {:method => :post} do |f| %>
翻译自:https://stackoverflow.com/questions/5912670/additional-parameter-in-form-for-in-rails
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- .NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 We...
- SQLServer之附加数据库
- Micro:bit 躲避砖块小游戏-附加功能
- SQLServer低版本附加高版本的数据库常用处理方法
- Firefox 64 附加组件管理器界面更新,可直接移除扩展
- javascript – 如何在CKEditor中将文本附加到html源代码?
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Numerical Methods and Methods of Approximation in Science and En
Karan Surana / CRC Press / 2018-10-31
ABOUT THIS BOOK Numerical Methods and Methods of Approximation in Science and Engineering prepares students and other readers for advanced studies involving applied numerical and computational anal......一起来看看 《Numerical Methods and Methods of Approximation in Science and En》 这本书的介绍吧!