更新 ruby on Rails 中的状态
我正在使用 AASM gem 来管理我的模型之一的状态。现在,我在 javascript 弹出窗口中使用 form_for 来更改状态,但它不起作用:
<h2>Set the state:</h2>
<%= form_for(@tracker) do |f| %>
<% if @tracker.errors.any? %>
<div id="error_explanation">
<h2>Uh-oh. We've got some problems</h2>
<% @tracker.errors.full_messages.each do |msg| %>
<%= msg %><br />
<% end %>
</div>
<% end %>
This tracker is currently: <%= @tracker.state %><br />
<%= select_tag :state, options_for_select(Tracker::STATEDESCRIPTIONS.map { |event| [event.to_s.humanize, event]}) %>
<%= f.submit %>
<% end %>
不过,我真正想做的是将表单全部包含在一个按钮中,但我不确定用什么来做到这一点? button_to
?
I'm using the AASM gem to manage states on one of my models. Right now, I'm using a form_for in a javascript popup to change the state, but it's not working:
<h2>Set the state:</h2>
<%= form_for(@tracker) do |f| %>
<% if @tracker.errors.any? %>
<div id="error_explanation">
<h2>Uh-oh. We've got some problems</h2>
<% @tracker.errors.full_messages.each do |msg| %>
<%= msg %><br />
<% end %>
</div>
<% end %>
This tracker is currently: <%= @tracker.state %><br />
<%= select_tag :state, options_for_select(Tracker::STATEDESCRIPTIONS.map { |event| [event.to_s.humanize, event]}) %>
<%= f.submit %>
<% end %>
What I'd really like to do, though, is contain the form all in a single button, but I'm not sure what to use for that? button_to
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
f.select
而不是select_tag
。这样,生成的select
HTML 标记将与form_for(@tracker)
关联,并且所选状态将正确映射到@tracker
> 在有问题的控制器操作中。You should use
f.select
instead ofselect_tag
. That way, the resultingselect
HTML tag will be associated with theform_for(@tracker)
, and the chosen state will be correctly mapped to@tracker
in the controller action in question.