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 error in Ruby on Rails!

NoMethodError in Statuses#edit

Showing c:/treebook/app/views/statuses/_form.html.erb where line #13 raised:

undefined method `user_id' for #<Status:0x4151d90> Extracted source (around line #13):

10: </ul> 11: </div> 12: <% end %> 13: <%= f.input :user_id %> 14: <%= f.input :content %> 15: <div class="form-actions"> 16: <%= f.button :submit %>

the 13th line is where the error is..

I created and edited this .rb file along with 'Installing simple_form'

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

end

[status.rb]

class Status < ActiveRecord::Base attr_accessible :content, :user_id

end

Please give me your solution!

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Dongju Seo sorry for the trouble! Jim fixes that issue in the following video:

http://teamtreehouse.com/library/programming-2/build-a-simple-version-of-facebook/customizing-forms/getting-the-latest-changes

Try following along there and let us know if you still have problems.

I just found that add_user_id_to_statuses.rb was named as 'add_user_to_statuses.rb'! Could this be the cause of that error? so,, I typed 'rake db:reset' and 'rake db:migrate', and the latter aborted.

c:\Projects\treebook>rake db:reset
Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - c:/Projects/treebook/db/development.sqlite3>
Couldn't drop db/test.sqlite3 : #<Errno::ENOENT: No such file or directory - c:/

Projects/treebook/db/test.sqlite3> db/development.sqlite3 already exists -- create_table("statuses", {:force=>true}) -> 0.1290s -- add_index("statuses", ["user_id"], {:name=>"index_statuses_on_user_id"}) -> 0.0980s -- create_table("users", {:force=>true}) -> 0.1320s -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})

   -> 0.0670s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
-> 0.0940s
-- initialize_schema_migrations_table()
   -> 0.1960s
-- assume_migrated_upto_version(20130603080528, ["c:/Projects/treebook/db/migrate"])
 -> 0.2800s
You have 1 pending migrations:
20130603223719 AddUserIdToStatuses
Run `rake db:migrate` to update your database then try again.

c:\Projects\treebook>rake db:migrate
==  AddUserIdToStatuses: migrating         ============================================
-- add_column(:statuses, :user_id, :integer)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: user_id: ALTER TABLE "statuses" ADD "user_id" integerc:/Projects/treebook/db/migrate/20130603223719_add_user_id_to

_statuses.rb:3:in change' C:inmigrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)

PS. when I wrote one status, It gave me a similar error.

NoMethodError in Statuses#index

Showing c:/Projects/treebook/app/views/statuses/index.html.erb where line #10 raised:

undefined method `full_name' for nil:NilClass Extracted source (around line #10):

7: 
8: <% @statuses.each do |status| %>
9: <div class="status">
10:   <strong><%= status.user.full_name %></strong>
11:     <p><%= status.content %></p>
12:     <div class="meta">
13:         <%= link_to time_ago_in_words(status.created_at) + " ago", status %>
Rails.root: c:/Projects/treebook
Jason Seifer
Jason Seifer
Treehouse Guest Teacher

It looks like you already have the user_id column in your statuses table. Try doing a rake db:reset and rake db:migrate and let us know if it works.

Thanks, I just fixed it.