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!

I just found that add_user_id_to_statuses.rb was named as 'add_user_to_statuses.rb'! Could this be the cause of the 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:in `migrate'
    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

2 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Dongju Seo try manually deleting the db/development.sqlite3 and db/test.sqlite3 and doing rake db:create:all and rake db:migrate again.

Jason Seifer , It happens to me, I have created a psql database, and manually added in database.yml, but when I run heroku run rake db:migrate, it throws the error (

PG::DuplicateColumn: ERROR:  column "user_id" of relation "statuses" already exists
: ALTER TABLE "statuses" ADD "user_id" integer
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::D