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

NoMethodError in Statuses#index

I have started getting an error saying NoMethodError in Statuses#index. It says undefined method `full_name' for nil:NilClass. I would appreciate any help.

my code for index.html.erb is

<div class="page-header">
  <h1>All Statuses</h1>
</div>

<%= link_to "Post A New Status", new_status_path, class: "btn btn-success" %>

<% @statuses.each do |status| %> 
<div class="status">
  <strong><%= status.user.full_name %></strong>
  <p><%= status.content %></p>
  <div class="meta">
    <%= link_to time_ago_in_words(status.created_at) + " ago", status %> 
    <span class="admin">
          | <%= link_to "Edit", edit_status_path(status) %> | 
          <%= link_to "Delete", status, method: :delete, data: { confirm: "Are you sure your want to delete this status?"} %>
    </span>
  </div>
</div>
<% end %> 

my user.rb code

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :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

  validates :first_name, presence: true

  validates :last_name, presence: true

  validates :profile_name, presence: true,
                           uniqueness: true,
                           format: {
                             with: /^[a-zA-Z0-9_-]+$/,
                             message: 'Must be formatted correctly.'
                           }

  has_many :statuses

  def full_name
    first_name + " " + last_name
  end


end

1 Answer

Can you also post your status model and both controllers?