Adding a css class to the devise forms

307 views
Skip to first unread message

JonathanSimmons

unread,
Feb 21, 2012, 12:09:21 PM2/21/12
to Devise
So I'm using my own devise views. But I can't for the life of me work
out how to get the registrations or session for to acknowledge a class
i'm trying to put on it.

Basically the form defaults as

<%= form_for(resource, :as => resource_name, :url =>
registration_path(resource_name)) do |f| %>

I simply want to add a class using class: 'newClass' (or :class =>
'newClass' for older syntax)

<%= form_for(resource, :as => resource_name, :url =>
registration_path(resource_name), :class => 'newClass') do |f| %>

but this doesn't work the form still loads with just user_new as the
class, and newClass is nowhere to be found.

Anyone know how I can override this.

For those curious I'm using bootstrap css and I'm trying to add
the .form-inline class to the sign in form save having to rewrite the
form elements css. I can get around this obviously but am more curious
why devise won't let me override the css class.

José Valim

unread,
Feb 21, 2012, 12:15:12 PM2/21/12
to Devise
This is rather a Rails question. Check out the docs for form_for:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

Jérôme Lanteri

unread,
Jun 28, 2016, 3:55:00 AM6/28/16
to Devise
I think you have to include with html_options option like:
:html_options => {class: => "newClass", :id => "newID", :style => "color: red" }

I see the date of your question, but i think you never find, because if you find, sure you will post an answer your own question here for help other devs you have the same problem (i'm sure...).

Hope this help...
Reply all
Reply to author
Forward
0 new messages