内容简介:翻译自: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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Effective JavaScript
David Herman / Addison-Wesley Professional / 2012-12-6 / USD 39.99
"It's uncommon to have a programming language wonk who can speak in such comfortable and friendly language as David does. His walk through the syntax and semantics of JavaScript is both charming and h......一起来看看 《Effective JavaScript》 这本书的介绍吧!