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 Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

Getting this error message NoMethodError in Statuses#show

Hi, I keep getting this error message when trying to get my project to show the full names.

undefined method `full_name' for nil:NilClass

<p>
    <strong>Name:</strong>
    <%= @status.user.full_name %>
</p>

this is how i'm calling for my full name

<%= @status.user.full_name %> and on the index page <%= status.user.full_name %>

I have included all of these snippets of code into my project as well

status.rb

class Status < ActiveRecord::Base attr_accessible :content, :user_id belongs_to :user end

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

# Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name # attr_accessible :title, :body

has_many :statuses

def full_name first_name + " " + last_name end end

I've tried using rake db:reset and rake db:migrate but nothing seems to solve the error problem. Thank you for your help!

Could you run the following command in your shell/command prompt and post the results

     rails -v

Rails 4.0.4

1 Answer

Lachlan Dawson as I suspected. The version of Rails in the videos is 3.2. The attr_accessible has been changed to strong parameters in the latest version. Also numerous other things have changed. If you don't have a great grasp of Rails you would be best to start over with the correct version of Rails. Otherwise it will cause you no end of trouble.

Hope this helps