简体   繁体   中英

Send form with submit button

I'm trying to submit those two forms shown below through an input button. Whereas the value on the button changes as expected when pressed nothing happens. When I try to add the f.submit an extra box appears under the button. So how can I do to link that button to the submit action? and also is there a better way of setting a value for the input to button that what I have done?

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

Thanks for your help!

Your button isn't connected with the form in any way so that's why nothing happens.

I think the best way is to do it with some javascript. Look for the onclick function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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