Easy way to extract or customize the controllers?

702 views
Skip to first unread message

Brian Armstrong

unread,
Jul 27, 2010, 2:40:59 AM7/27/10
to Devise
Is there an easy way to extract all of Devise's controllers so they
can be customized?

I want to do a multi-step signup process on our app, and adjust params
and checks that occur in the registration controller.

I can always copy the files out of the GitHub project and us custom
routes I suppose:
http://github.com/plataformatec/devise/tree/master/app/controllers/devise/

But was just wondering if there is a better way since I didn't see
anyone else doing this.

Brian Armstrong

unread,
Jul 27, 2010, 2:46:08 AM7/27/10
to Devise
For example - another small change that appears to require customizing
the controllers:

I set my email and password fields to protected so they can't be mass
assigned (but other attributes can). But now I need to set them
manually in the registrations controller - I need to customize it
right?

Is this common or is there something I'm missing about how Devise is
supposed to work?

On Jul 26, 11:40 pm, Brian Armstrong <barmstr...@gmail.com> wrote:
> Is there an easy way to extract all of Devise's controllers so they
> can be customized?
>
> I want to do a multi-step signup process on our app, and adjust params
> and checks that occur in the registration controller.
>
> I can always copy the files out of the GitHub project and us custom
> routes I suppose:http://github.com/plataformatec/devise/tree/master/app/controllers/de...

Carlos Antonio da Silva

unread,
Jul 27, 2010, 8:03:21 AM7/27/10
to plataforma...@googlegroups.com
For Rails 3, you just need to inherit your controller from any Devise Controller you need and override the specific actions you need, like this:

class MyRegistrationsController < Devise::RegistrationsController
  def new
    # do your stuff here
  end
end

Then you have to tell devise your controller exists:

devise_for :users, :controllers => { :registrations => 'my_registrations' }

Or sth like that, please give some search in the list, there are some other threads with more examples if you need.
Also, if you achieve this, I'd ask you to update the wiki with some information about it, this can help others with the same doubt. Thanks.
--
At.
Carlos A. da Silva

tekknikk

unread,
Jul 27, 2010, 5:13:04 PM7/27/10
to Devise
What is the approach of Rails 2.3.8?

Thanks

On Jul 27, 5:03 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> For Rails 3, you just need to inherit your controller from any Devise
> Controller you need and override the specific actions you need, like this:
>
> class MyRegistrationsController < Devise::RegistrationsController
>   def new
>     # do your stuff here
>   end
> end
>
> Then you have to tell devise your controller exists:
>
> devise_for :users, :controllers => { :registrations => 'my_registrations' }
>
> Or sth like that, please give some search in the list, there are some other
> threads with more examples if you need.
> Also, if you achieve this, I'd ask you to update the wiki with some
> information about it, this can help others with the same doubt. Thanks.
>

Carlos Antonio da Silva

unread,
Jul 27, 2010, 5:23:03 PM7/27/10
to plataforma...@googlegroups.com
Unfortunately, there is no such feature in Devise for Rails 2.3.x.
You have to roll your own controllers and make use of Devise helpers.

José Valim

unread,
Jul 27, 2010, 5:25:26 PM7/27/10
to plataforma...@googlegroups.com
YOu can do that by simply copying the controller from Devise source code to your application.
--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

Brian Armstrong

unread,
Jul 29, 2010, 12:42:11 AM7/29/10
to Devise
Ok thanks for the replies everyone.

I think you are right - the correct way is to subclass the Devise
controller and only override the pieces I need (as it describes in the
documentation) but leave the rest intact.

Not sure why but for some reason it was scary for me to have all that
code hidden in the gem and not available to view in my controllers
directory :) Sort of threw me off at first. But yes, I will
contribute something to the wiki if I end up extracted the whole group
of controllers. Thanks I really appreciate the help!
Brian

On Jul 27, 2:25 pm, José Valim <jose.va...@gmail.com> wrote:
> YOu can do that by simply copying the controller from Devise source code to
> your application.
>
> On Tue, Jul 27, 2010 at 11:23 PM, Carlos Antonio da Silva <
>
>
>
>
>
> carlosantoniodasi...@gmail.com> wrote:
> > Unfortunately, there is no such feature in Devise for Rails 2.3.x.
> > You have to roll your own controllers and make use of Devise helpers.
>

tekknikk

unread,
Jul 27, 2010, 5:29:26 PM7/27/10
to Devise
i was about to try that. thanks

On Jul 27, 2:25 pm, José Valim <jose.va...@gmail.com> wrote:
> YOu can do that by simply copying the controller from Devise source code to
> your application.
>
> On Tue, Jul 27, 2010 at 11:23 PM, Carlos Antonio da Silva <
>
>
>
>
>
> carlosantoniodasi...@gmail.com> wrote:
> > Unfortunately, there is no such feature in Devise for Rails 2.3.x.
> > You have to roll your own controllers and make use of Devise helpers.
>
Reply all
Reply to author
Forward
0 new messages