ruby-on-rails – Rails中form_for的附加参数

栏目: Ruby · 发布时间: 6年前

内容简介:翻译自: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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security Testing Cookbook

Web Security Testing Cookbook

Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99

Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具