Question

OS: Windows 8.1 Ruby 2.0.0 Rails 4.1 Devise

After I created the application, I installed Devise:

rails g devise:install
rails g devise:views

The devise views were generated. What I don't have is a registrations controller in the controllers folder. Wasn't devise supposed to create a registrations controller?

Was it helpful?

Solution

You can either use Devise's default controllers or add your own. Here is the link to the registrations controller: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

Keep in mind, Devise handles actions a little differently if you're planning on adding records to the User model.

You'll need to add something like this to the registration controller if you plan on adding something like a username:

before_filter :update_sanitized_params, if: :devise_controller?

def update_sanitized_params
  devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username,
                                                         :email,
                                                         :password,
                                                         :password_conf)}
end

You'll also need to add this to you routes.rb:

devise_for :users, :controllers => {:registrations => "users/registrations"}

OTHER TIPS

Devise not generate controller by default for app, app use built-in devise controllers. If you need monkeypatch devise controller you need create them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top