如何添加额外的参数到button

如何添加额外的参数到button

本文介绍了如何添加额外的参数到button_to表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个提交按钮。它更新了提交中的一个字段; submission.state =:已提交



现在,我可以制作自定义路线和自定义操作,那。但是这看起来真的很厉害。特别是因为我还会有一个拒绝按钮,可能还有更多。需要一条定制路线&每个人的行为似乎都是愚蠢的。



如果我可以做一些事情会更好。

  button_toSubmit,submission_url(submission),:method => :put,:submission => {:state => :已提交} 

哪些内容会发送到提交的更新方法并仅更新所需的字段。

但这不起作用。我怎样才能使它工作?或者你有更好的方法来解决这个问题?

由@AugustinRiedinger提及已经合并,现在可以从 Rails 4.1.0 使用。现在只需添加 params 选项:

  params:{state::提交} 


I want to have a Submit button. It updates one field on the submission; submission.state = :submitted

Now, I could make a custom route and a custom action and just post to that. But that seems really heavy-handed. Especially since I'll also have a reject button and possibly more. Needing a custom route & action for each of those seems downright silly to me.

It would be much nicer if I could do something like

button_to "Submit", submission_url(submission), :method => :put, :submission => { :state => :submitted }

Which would post to the submission's update method and update only the desired field.

But that doesn't work. How can I make it work? Or do you have a better idea of how to do this?

解决方案

The pull request mentioned by @AugustinRiedinger has been merged and is now available as of Rails 4.1.0. Now just add the params option:

params: { state: :submitted }

这篇关于如何添加额外的参数到button_to表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 07:27