Rails - params[:commit] 的目的是什么 [英] Rails - What is the purpose of params[:commit]

查看:78
本文介绍了Rails - params[:commit] 的目的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到每次将 Rails 表单发送到服务器时,提交按钮的名称(通常是按钮上显示的字符串)都包含在 params 哈希中,作为提交".

I notice that every time a Rails form is sent to the server, the name of the submit button (usually the string that is displayed on the button) is included in the params hash as "commit".

例如(最后一个条目)

{"utf8"=>"✓",
 "authenticity_token"=>"eZABpBuW7afziDMUJtc1BNEKvGyI7NlTd9+NOYqnMxs=",
 "order"=>{"name"=>"marco",
 "email"=>"marwus@co.xa",
 "phone"=>"0839457382",
 "collection"=>"0",
 "address"=>"18 main street, paarl",
 "city"=>"paarl",
 "country"=>"South Africa",
 "zip"=>"7646",
 "instructions"=>""},
 "terms"=>"on",
 "commit"=>"Next: 3. Payment"}

这样做的目的是什么?

这是我格式不正确的结果吗?

Is it a result of me formatting my forms incorrectly?

这是我针对这个特定示例的提交按钮,取自我的 form_for

Here is my submit button for this specific example, taken from my form_for block

<%= f.submit 'Next: 3. Payment', :class => 'right button' %>

(类right button 来自foundation 表单.

推荐答案

这是一种区分按下提交按钮的方法.如果您有非常不同的操作,例如:

Its a way to discriminate which submit button was pushed. Could be useful if you have very different actions like:

  • 保存草稿
  • 发布

这篇关于Rails - params[:commit] 的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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