Daniel Gomez Firmat
Daniel Gomez Firmat

Reputation: 43

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!

Upvotes: 0

Views: 52

Answers (1)

C.Hackman
C.Hackman

Reputation: 11

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.

Upvotes: 1

Related Questions