Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

first_name attribute in the devise user model

Hello All, probably just a noob question.

I generated a devise user model as explained in the video and added the attributes first_name and last_name. The signing up process goes smooth without errors but the first_name and last_name entered in the form are not getting stored in the DB and show up as nil. The email and password are being stored just fine.

I am guessing this has probably something to do with the attr_accessor in user.rb In the video, Jason had the attr_accessor for email, password etc already populated and he added first_name and so to it. But in my case, it did not even have that line. So I added that line with all the attributes. If I did that, the email and password also were being stored as nil and upon researching online, apparently these were being overwritten. Removing the email and password attributes fixed the issue but the issue with first_name still persists with or without attr_accessor. Not sure what I am missing.

Snippet of user.rb:

''' class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

attr_accessor :first_name, :last_name

has_many :statuses

def full_name first_name + " " + last_name end

end '''

Thanks, CJ

1 Answer

Sorry...did not realize this question was already answered in the following post. https://teamtreehouse.com/community/strongparameters-and-treebook

I did look in the community if anyone had a similar problem but looks like I did not look hard enough. The answer in the post resolved my issue. Thanks