Rails 3 form_tag 带远程不发送提交详细信息

发布于 2024-10-15 04:43:03 字数 858 浏览 6 评论 0原文

当使用正常的非远程请求时,此表单 100% 有效。但是当我设置远程=>时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

This form works 100% when using the normal non-remote request. However when I set remote => true it is not longer sending the submit value. Should I do this completely differently, or is there something I'm missing?

<%= 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 %>

params

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

should send

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-10-22 04:43:03

可能有一种更简洁的方法,我也简单地尝试了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>

There is probably a more concise way, I also tried briefly the button_to method but couldn't figure out how to squeeze it all in.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文