Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How to style form submit button

I have a Rails 4, that uses Rails' default form (I am NOT using Simple Form).

In one of my forms, I would like to style the following submit button:

<td>
  <%= f.submit %>
</td>

I tried to apply an id to the td but this obviously applied my new style to the entire table cell.

Then, I tried to apply an id to the submit button itself, as recommended here, as follows:

<td>
  <%= f.submit, :id => 'create_post' %>
</td>

This gave me the following error:

SyntaxError in CalendarsController#show
/Users/TXC/code/rails/calendy/app/views/calendars/show.html.erb:69: syntax error, unexpected =>, expecting :: or '[' or '.' ...er.append=( f.submit, :class => 'create_post' );@output_buff... ... ^
<%= f.submit, :class => 'create_post' %>

What is a good way to apply a custom style to a submit button in Rails?

like image 472
Thibaud Clement Avatar asked Jan 29 '26 14:01

Thibaud Clement


1 Answers

Try changing your syntax to this:

<%= f.submit, id: 'create_post' %>
like image 56
xeitor Avatar answered Jan 31 '26 04:01

xeitor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!