问题描述
我想要一个提交
按钮。它更新了提交中的一个字段; 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表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!