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

undefined method `name'

Hey Guys,

I am new too ruby on rails and I am having an issue with the build a simple ruby on rails application. For some reason i'm getting an NoMethodError in Statuses#new. Can somebody please take a look and tell me how to fix this issue.

https://github.com/curtisaallen/treebook

Thank you, Curtis Allen Curtis Allen

appbites
appbites
2,949 Points

Did you define variable for 'name' in your app/models/user.rb? :)

1 Answer

Your form is calling the 'name' method on @status instance variable on line 15 of '_form.html.erb'. Your Status model doesn't have a 'name' attribute. Here's your schema: http://cl.ly/image/1f1C0C1j0A1m

You ran a migration removing the 'name' column from your Status model.

db/migrate/20130531015437_add_user_id_to_status.rb

class AddUserIdToStatus < ActiveRecord::Migration
def change
add_column :statuses, :user_id, :integer
add_index :statuses, :user_id
**remove_column :statuses, :name**
end
end

Hey MB, This maybe a stupid question, but what command do I need to run to add name back to my database? Thank you, Curtis Allen

Also, thanks everybody for all your help.

Never mind guys. The next video shows the same issue and what to do to fix it. Thanks again for all the help. Curtis Allen

You'll need to run another migration to add the 'name' column in your statuses table.

> rails generate migration add_name_column_to_statuses

class AddNameColumnToStatuses < ActiveRecord::Migration
    def change
        # syntax: add_column(table_name, column_name, type)
        add_column(:statuses, :name, :string)
    end
end

> rake db:migrate