I have an ActiveRecord object:
@user = User.find_by_id(1)
I want to access the name of the user from this object; how do I do it?
@user.name # Gives Error = No mathod 'name'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you use
User.findinstead ofUser.find_by_idand then perform.nameon that, you should receive your output.But from not seeing your entire DB, it might be you’re simply getting a no method because the field does not exist. In that case you should change the method name accordingly from: