繁体   English   中英

发送带有提交按钮的表格

[英]Send form with submit button

我正在尝试通过输入按钮提交下面显示的两种形式。 当按下按钮时,按钮上的值将按预期更改。 当我尝试添加f.submit时,按钮下方会出现一个额外的框。 那么我该如何将该按钮链接到Submit操作? 还有一种更好的方法来为按钮输入设置一个我所做的值?

<input class="btn btn-default" type="submit" value=" <% if current_user.following?(@user) %> Unfollow <%else%> Follow <%end%>">

<% unless current_user?(@user) %>

    <% if current_user.following?(@user) %>

      <%= form_for(current_user.active_relationships.find_by(followed_id: @user.id),
         html: { method: :delete },
         remote: true) do |f| %>


      <% end %>

    <% else %>

      <%= form_for(current_user.active_relationships.build, remote: true) do |f| %>
      <div><%= hidden_field_tag :followed_id, @user.id %></div>

      <% end %>

    <% end %>
<% end %>

谢谢你的帮助!

您的按钮没有以任何方式与表单连接,因此没有任何反应。

我认为最好的方法是使用一些JavaScript。 寻找onclick函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM