Devise and SimpleForm

741 views
Skip to first unread message

Floydzy

unread,
Jan 13, 2012, 1:48:14 PM1/13/12
to SimpleForm
Hi there,

I'm new to Rails and I'm trying to use Devise and SimpleForm. Ive
searched a lot but didn't find any answer to my problem.

Here it is: I use the SimpleForm Gem, and I customized the template
lib/templates/erb/scaffold/_form.html.erb so that, everytime I
generate a scaffold, this file (_form.html) is used as a template for
my formulary.
I would like the same behaviour with the Devise gem: when I generate
the views with the command "rails generate devise:views", I would like
the formularies to fit my own template and not the SimpleForm
default's one.

It looks like Devise is using the default template of the Gem. How can
I modify it? Shall I download the gem as a plugin?

Hope u guys were able to understand my problem, otherwise I'll try to
develop it :)

Many thanks for your time,
Floydzy

Carlos Antonio da Silva

unread,
Jan 13, 2012, 1:55:42 PM1/13/12
to plataformate...@googlegroups.com
When you run the devise:views generator, it copies all views to your app/views folder. From this time on, these are the views that will be used, and you can change them as you want.

Devise also comes with an option when you run the views generator, to generate them using SimpleForm default templates, as you can see here:
--
At.
Carlos Antonio

Floydzy

unread,
Jan 13, 2012, 6:09:07 PM1/13/12
to SimpleForm
Thanks for your help Carlos :)

On 13 jan, 19:55, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> When you run the devise:views generator, it copies all views to your
> app/views folder. From this time on, these are the views that will be used,
> and you can change them as you want.
>
> Devise also comes with an option when you run the views generator, to
> generate them using SimpleForm default templates, as you can see here:https://github.com/plataformatec/devise/blob/master/lib/generators/de...

mcbsys

unread,
Feb 28, 2012, 9:15:28 PM2/28/12
to plataformate...@googlegroups.com
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,

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 app/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| %>

Let me know if I misunderstood anything.

Mark Berry

Carlos Antonio da Silva

unread,
Feb 29, 2012, 6:10:06 AM2/29/12
to plataformate...@googlegroups.com
Perfect Mark, thanks for clarifying.

-- 
At.
Carlos Antonio

Bharat Ruparel

unread,
Feb 29, 2012, 8:06:37 AM2/29/12
to plataformate...@googlegroups.com
Hello Carlos,
Can we put this somewhere on the wiki?
Thanks.
Bharat


From: Carlos Antonio da Silva <carlosanto...@gmail.com>
To: plataformate...@googlegroups.com
Sent: Wednesday, February 29, 2012 5:10 AM
Subject: Re: Devise and SimpleForm

Perfect Mark, thanks for clarifying.

-- 
At.
Carlos Antonio

On Tuesday, February 28, 2012 at 11:15 PM, mcbsys wrote:
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,

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 app/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| %>

Let me know if I misunderstood anything.

Mark Berry

On Friday, January 13, 2012 3:09:07 PM UTC-8, Floydzy wrote:
Thanks for your help Carlos :)

On 13 jan, 19:55, Carlos Antonio da Silva
<carlosantoniodasi...@gmail. com> wrote:
> When you run the devise:views generator, it copies all views to your
> app/views folder. From this time on, these are the views that will be used,
> and you can change them as you want.
>
> Devise also comes with an option when you run the views generator, to
> generate them using SimpleForm default templates, as you can see here:https://github.com/ plataformatec/devise/blob/ master/lib/generators/de...
>
>
>
>
>
>
>
>
>
> On Fri, Jan 13, 2012 at 4:48 PM, Floydzy <usinasi...@gmail.com> wrote:
> > Hi there,
>
> > I'm new to Rails and I'm trying to use Devise and SimpleForm. Ive
> > searched a lot but didn't find any answer to my problem.
>
> > Here it is: I use the SimpleForm Gem, and I customized the template
> > lib/templates/erb/scaffold/_ form.html.erb so that, everytime I

Carlos Antonio da Silva

unread,
Feb 29, 2012, 9:10:27 AM2/29/12
to plataformate...@googlegroups.com
Hey Bharat,

sure, great idea! Feel free to open a page there with this explanation :)

Thanks.

-- 
At.
Carlos Antonio

Reply all
Reply to author
Forward
0 new messages