Andrew Hendrie
Andrew Hendrie

Reputation: 6415

Adding User's First Name to Devise Confirmation Email Template

I'm running Rails 4.2.0 with the latest version of Devise.

I'm using the confirmable module - so after a user registers they are sent a confirmation email.

Here's the view code for that (in Slim... not ERB)

p 
  | Hi
  = @user.first_name
  | ,

p In order for me to send you the details, I'm going to need you to confirm your email address by clicking the link below: 
= link_to "#{confirmation_url(@resource, confirmation_token: @token)}", confirmation_url(@resource, confirmation_token: @token)

Here's the Users Controller code:

class Users::RegistrationsController < Devise::RegistrationsController

  private
  def user_params
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
  end

end

There is a first name column in the database (migration has been run); however, this doesn't work. The place where the users first name should be is blank.

How can I configure the view to include the users first name?

Upvotes: 2

Views: 962

Answers (3)

Andrew Hendrie
Andrew Hendrie

Reputation: 6415

Did some digging through the Devise Gem and found that I needed to over-ride the following controller actions (app/controllers/users/registrations_controller.rb):

 private

 def sign_up_params
   params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
 end

 def account_update_params
   params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
 end

...and ensure that my application is using my new Registrations controller with this in routes.rb

devise_for :users, :controllers => { registrations: 'user/registrations' }

Upvotes: 1

FunTimeFreddie
FunTimeFreddie

Reputation: 61

current_user.first_name has worked for me in the past. Any good?

Upvotes: 0

Austio
Austio

Reputation: 6095

Devise uses resources to abstract the thing that it is managing.

Assuming your @resource is being set correctly, you should be able to do

@resource.first_name

Upvotes: 3

Related Questions