开发者

Updating state in ruby on rails

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 开发者_StackOverflow中文版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?


You should use f.select instead of select_tag. That way, the resulting select HTML tag will be associated with the form_for(@tracker), and the chosen state will be correctly mapped to @tracker in the controller action in question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜