-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Simple Form with Devise
The following is a write-up by Mark Berry:
A little clarification (I hope): if SimpleForm is detected when you run rails generate devise:views, Devise will automatically generate the SimpleForm version of the Devise views. There is nothing to specify to get the SimpleForm version. (Tested with Devise 1.5.3 and SimpleForm 2.0.1.)
If, like me, you had already generated the Devise views before installing SimpleForm, you'll need to re-generate the views after installing SimpleForm by running rails generate devise:views. If you would see few conflicts with files then you should just rewrite them.
Also, if you just delete the locally-generated Devise views (app/views/devise), even if SimpleForm is installed, Devise will not use SimpleForm-styled views "in the background." You have to generate local Devise views even if you don't want to customize them.
Finally, if you're using Twitter Bootstrap and the Bootstrap extensions to SimpleForm ( rails generate simple_form:install --bootstrap ), when you generate Devise views (rails generate devise:views), Devise does not add the Bootstrap styles automatically. If you want horizontal forms, for example, you could add this line to config/initializers/simple_form.rb:
config.form_class = 'simple_form form-horizontal'
Unfortunately, it seems that can't be overridden at the view level (in case you sometimes want vertical forms). The other option is to manually add the Bootstrap class to each Devise view, e.g. in app/views/devise/sessions/new.html.erb, change this line
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
to this:
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'form-horizontal' }) do |f| %>
This page was created by the OSS community and might be outdated or incomplete. Feel free to improve or update this content according to the latest versions of SimpleForm and Rails to help the next developer who visits this wiki after you.
Keep in mind to maintain the guides as simple as possible and to avoid additional dependencies that might be specific to your application or workflow (such as Haml, RSpec, Guard and similars).