7

I would like to customize my registrations controller for Devise in Rails. I understand that you must create a controller like this:

class AccountsController < Devise::SessionsController
  def create
    super
  end
end

Well, that's all very good. But then let's say I want to fully control what happens in my #create action. How do I do that? How do I manually create a model and pass it all the params? Would Account.create(params[:account]) handle it smoothly? Is there some internal stuff going on I should know about or is my only option to call #super inside the action?

orion3
  • 9,797
  • 14
  • 67
  • 93

2 Answers2

5

As long as you fulfil your required fields you can call Account.create in your example, I'm pretty sure the default Devise required fields are login, password and password_confirmation

We do this in a CRUD screen for creating devise users,

@admin = Admin.new(params[:admin])
if @admin.save
  redirect_to admin_admins_path, :notice => 'New Administrator has been added'
else
  render :action => "new"
end

and you don't want to extend the Devise session controller, a normal controller extending ApplicationController is fine or you can extend Devise::RegistrationsController and overwrite the methods you want to tweak in a registrations_controller.rb file

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • Yes, thanks. SessionsController was a copypaste typo, I understand it should be RegistrationsController. – orion3 Jan 11 '11 at 08:40
1

You can also have a look at the source on Github, if you want to be sure you're overriding things properly, and be sure you're not missing any processing...

https://github.com/plataformatec/devise/tree/master/app/controllers

Oto Brglez
  • 4,113
  • 1
  • 26
  • 33
sands
  • 342
  • 3
  • 9
  • 1
    P.S. - Note that the URL specifies the 1.3.0 release. Be sure to navigate to the source for the version you are using. – sands Aug 21 '11 at 04:13