0

I found something pretty weird and can't explain it:

Following form with a submit button

  <!-- Nested form -->
  <%= f.fields_for :area_attributes do |builder| %>
  <div class="col-md-4">
    <div class="panel panel-default">
      <div class="panel_heading">
        <%= builder.label :name, "Name of the attribute" %>
        <%= builder.text_area :name %>
      </div>
      <div class="panel-body">
        <%= builder.label :value, "Value of the attribute" %>
        <%= builder.text_area :value %>
        <%= builder.check_box :_destroy %>
        <%= builder.label :_destroy, "Remove Question" %>
      </div>

    </div>
  </div>
  <% end %>

</section>
<div class="actions">
  <%= f.submit %>
</div>

Now this worked great, then i switched to bootstrap and wanted to change the class of the submit div to something else.

<div class="submit">
  <%= f.submit %>
</div>

And now the button didn't trigger anything anymore?! No request was sent, nothing happened (and I don't know where the .actions is coming from, I took it from a tutorial). Then I changed it to

<div class="submit">
  <%= f.submit() %>
</div>

And now its working again? Even the docs list it without parentheses, I'm new to ruby but as far as I know the parentheses is optional, right? Why is it needed here??

UPDATE Feb. 5 Okay this has nothing to do with parentheses. I tracked it down and it seems that the button is only working when refreshing the page and NOT when I navigate to the page ordinarily. I had a very similar problem and I could solve it using the jquery-turbolinks gem As described here

Im working in the same project, the gem is installed, what is going on here? I checked the HTML output and there is no difference between the working version and the not working version:

<input class="positive-button" name="commit" type="submit" value="Create Area">

Greetings

Community
  • 1
  • 1
Shady
  • 794
  • 2
  • 8
  • 23
  • 1
    Parentheses are, indeed, optional. Can't say why you're seeing this weirdness. Post your full code and the rendered html to better help you – DiegoSalazar Feb 04 '14 at 19:45
  • Is that div really necessary? Would it help adding it directly to the submit button? Like `:html => { :class => "submit"}`. – rlecaro2 Feb 04 '14 at 20:31
  • Same thought at rlecaro. Have you looked at the html generated for the form to see what is happening to the `submit` button/div or the `form` between the 3 samples of code? – HM1 Feb 04 '14 at 20:49

1 Answers1

0

Just changing the class of the div your submit button is wrapped in shouldn't stop the form helper from generating a valid submit button.

If the form action you're expecting stops working when you change the class, it's likely that something is preventing the default click action from firing. Check your Javascript to see if there is a click event handler bound to the .actions class (or .actions input[type=submit]). If so, modify that so it is using .submit instead.

QMFNP
  • 997
  • 8
  • 14