Reputation: 2200
I am trying to style form elements within this rails form_for but continually run into syntax error, nothing i try seems to be working:
_form.html.erb:
<%= form_for(@todo_list) do |f| %>
<div class="form-group">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="form-group">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div>
<%= f.submit, html: {class: "btn btn-default btn-xs"} %>
</div>
<% end %>
This just gives this error:
_form.html.erb:23: syntax error, unexpected tLABEL, expecting '=' ...buffer.append=( f.submit, html: {class: "btn btn-default btn... ...
All sorts of variations of class=
, class:
, html=>
, passing in html => {:class => "form-horizontal"}
, etc etc, all just seem to give the same syntax error.
The only exception is when I explicitly apply a label to the submit action, e.g.;
<%= f.submit 'Save', class: "btn btn-default btn-xs" %>
Then the class gets added successfully and my bootstrap styling works. However this neither locates the primary problem nor solves it as then I can't use rails' form_for dynamic naming of the submit action.
Classes I apply to divs seem to work fine, bootstrap is loaded fine. Can anyone help? Thanks
Upvotes: 0
Views: 237
Reputation: 8900
You get the error because submit
is a function and the first argument is the label. You cannot write f.submit,
as you did in your code example.
You need to supply at least nil
as a label if you're wanting to add the second argument. The correct way to do this would be:
<%= f.submit nil, html: {class: "btn btn-default btn-xs"} %>
From APIDock
submit(value=nil, options={}) public
Upvotes: 1