2

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?

Andrew Hendrie
  • 6,205
  • 4
  • 40
  • 71

3 Answers3

3

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
Austio
  • 5,939
  • 20
  • 34
  • this isn't working. do I need to change something in the confirmations controller? – Andrew Hendrie Apr 03 '15 at 03:35
  • In that same form if you are using pry, put a binding.pry to evaluate your resources. If not do '@user.inspect' and then '@resource.inspect' in the template to see what they are. - note single quotes are only way i could get this to save. Ignore those around the instance variables. – Austio Apr 03 '15 at 17:53
1

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' }
Andrew Hendrie
  • 6,205
  • 4
  • 40
  • 71
0

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