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


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

查看所有标签

猜你喜欢:

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

Numerical Methods and Methods of Approximation in Science and En

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》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具