0

使用正常的非远程请求时,此表单 100% 有效。但是,当我设置 remote => true 时,它​​不再发送提交值。我应该完全不同地做这件事,还是我遗漏了什么?

<%= form_tag [voteable, Vote.new], :remote => true do |f| %>
    <strong class="votes_balance"><%= voteable.votes_for - voteable.votes_against %></strong>
    <%= submit_tag :up, { :name => "thumb_direction", :class => "vote_up" } %>
    <%= submit_tag :down, { :name => "thumb_direction", :class => "vote_down" } %>
    <%= hidden_field_tag :voteable_type, voteable.class %>
<% end %>

参数

authenticity_token  /8Dkx/EQc+VqgZd8f/eoWevm8AIgOwK0rzXqlGUzDUA=
utf8    ✓
voteable_type   Article

应该发送

authenticity_token  /8Dkx/EQc+VqgZd8f/eoWevm8AIgOwK0rzXqlGUzDUA=
utf8    ✓
voteable_type   Article
thumb_direction     up
4

1 回答 1

0

可能有一种更简洁的方法,我也简单地尝试了 button_to 方法,但无法弄清楚如何将它全部挤进去。

<div id="votes" class="thumbs_up">

    <%= form_tag [voteable, Vote.new], :remote => true do |f| %>
        <%= hidden_field_tag :voteable_type, voteable.class %>
        <%= hidden_field_tag :thumb_direction, "up" %>
        <%= submit_tag :up, { :class => "vote_up" } %>
    <% end %>

    <strong class="votes_balance"><%= voteable.votes_for - voteable.votes_against %></strong>

    <%= form_tag [voteable, Vote.new], :remote => true do |f| %>
        <%= hidden_field_tag :voteable_type, voteable.class %>
        <%= hidden_field_tag :thumb_direction, "down" %>
        <%= submit_tag :down, { :class => "vote_down" } %>
    <% end %>

</div>
于 2011-02-01T16:16:08.463 回答