ActionController::InvalidAuthenticityToken in RegistrationsController#create

Per the comments in the core application_controller.rb, set protect_from_forgery to the following: protect_from_forgery with: :null_session Alternatively, per the docs, simply declaring protect_from_forgery without a :with argument will utilize :null_session by default: protect_from_forgery # Same as above UPDATE: This seems to be a documented bug in the behavior of Devise. The author of Devise suggests disabling … Read more

Rails 4.0 with Devise. Nested attributes Unpermited parameters

config/routes.rb Create your own registration controller like so … (see Devise documentation for the details of overriding controllers here …) … which is more elegant way as opposed to doing it via the ApplicationController devise_for :users, controllers: {registrations: ‘users/registrations’} app/controllers/users/registrations_controller.rb Override the new method to create a Profile associated with the User model as below … Read more

Customizing Devise error messages in Rails 3?

You can configure the error messages in the locales file at: /config/locales/devise.en.yml Which should have something like below code and which you can easily modify to your liking: en: errors: messages: not_found: “not found” already_confirmed: “was already confirmed” not_locked: “was not locked” devise: failure: unauthenticated: ‘You need to sign in or sign up before continuing.’ … Read more

Always getting 401 Unauthorized with new install of Rails + Devise

Well this little exercise in frustration turned out to be a good lesson in RTFM. I had set up Devise with confirmable, and when I created my layouts I neglected to insert the following lines: <p class=”notice”><%= notice %></p> <p class=”alert”><%= alert %></p> … as it clearly states to do in the getting started guide. … Read more

rails 3 + devise: how to modify the mailer method for confirmation emails to add user’s second email address

Just in case anyone got here through Google – in the latest version of Devise, header_for takes two parameters. So your code would need to be: class MyMailer < Devise::Mailer backup_email = “…” def headers_for(action, opts) headers = { :subject => subject_for(action), :to => resource.email, :from => mailer_sender(devise_mapping), :bcc => backup_email, :reply_to => mailer_reply_to(devise_mapping), :template_path … Read more

How can I redirect a user’s home (root) path based on their role using Devise?

Your routes.rb file won’t have any idea what role the user has, so you won’t be able to use it to assign specific root routes. What you can do is set up a controller (for example, passthrough_controller.rb) which in turn can read the role and redirect. Something like this: # passthrough_controller.rb class PassthroughController < ApplicationController … Read more

Rails Devise: after_confirmation

I’m using Devise 3.1.2, it has a placeholder method after_confirmation which is called after the confirmation finished successfully. We just need to override this method in User model. class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable # Override Devise::Confirmable#after_confirmation def after_confirmation # Do something… end end See: Devise 3.5.9 Source Code: … Read more