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

Deleted User

Ruby on Rails Authentication System Problems

I've been hit a problem with the Ruby on Rails application videos.

I get the following error when trying to access http://localhost:3000/users/sign_up


NoMethodError in Devise/registrations#new

Showing C:/Sites/treebook/app/views/devise/registrations/new.html.erb where line #10 raised:

undefined method `last_name' for #<User:0x3b8a430>

Extracted source (around line #10):

7: <%= f.text_field :first_name %></div> 8: 9: <div><%= f.label :last_name %><br /> 10: <%= f.text_field :last_name %></div> 11: 12: <div><%= f.label :profile_name %><br /> 13: <%= f.text_field :profile_name %></div>

Rails.root: C:/Sites/treebook Application Trace | Framework Trace | Full Trace

app/views/devise/registrations/new.html.erb:10:in `block in app_views_devise_registrations_new_html_erb__431887295_31878396'

app/views/devise/registrations/new.html.erb:3:in `app_views_devise_registrations_new_html_erb__431887295_31878396'

Any ideas?

26 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Tom, has your database been migrated? If not try running the following:

rake db:migrate
Deleted User

Ok I have bypassed the above issue by taking out the last_name field for some reason unknown to me this was breaking the application.

My next issue however is indeed when I rake db:migrate to update the changes to the user statuses model.

I get the following errors.

C:\Sites\treebook>rake db:migrate == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: first_name: ALTER TABLE "users" AD D "first_name" varchar(255) C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:4:in block i n up' C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:3:inup' C:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

It looks like something happened to your database. Try running the following:

rake db:all
rake db:create:all
rake db:migrate

This will completely delete and recreate your database and migrate it up to the current version. You will have to recreate your users and some statuses.

Deleted User

thanks but when i try run rake db:all i get this

rake aborted! Don't know how to build task 'db:all'

can i delete the database manually and then run the create command?

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Sorry about that, I had a typo! It's the following:

rake db:drop:all
Deleted User

Ah ok, i've run all of those and still get this error when migrating the db.


C:\Sites\treebook>rake db:create:all

C:\Sites\treebook>rake db:migrate == CreateStatuses: migrating ================================================= -- create_table(:statuses) -> 0.0050s == CreateStatuses: migrated (0.0070s) ========================================

== AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "first_name " varchar(255) C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:4:in block i n up' C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:3:inup' C:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)

thanks for your help so far, any ideas?

Did you manually delete the migration file that creates the users table? I've done that before...check the git history and compare. Let us know!

Deleted User

I don't believe I have deleted the migration file, here is the link to the github:

https://github.com/tomheather/treebook

Try rake db:reset

Deleted User

C:\Sites\treebook>rake db:reset

Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - C:/S ites/treebook/db/development.sqlite3> db/development.sqlite3 already exists -- create_table("statuses", {:force=>true}) -> 0.2010s -- create_table("users", {:force=>true}) -> 0.1040s -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})

-> 0.0150s -- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_pa ssword_token", :unique=>true}) -> 0.0140s -- initialize_schema_migrations_table() -> 0.0010s -- assume_migrated_upto_version(20121231163913, ["C:/Sites/treebook/db/migrate"] ) -> 0.0140s You have 2 pending migrations: 20121231172750 AddDeviseToUsers 20121231220507 AddUserIdToStatuses Run rake db:migrate to update your database then try again.


C:\Sites\treebook>rake db:migrate

== AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: first_name: ALTER TABLE "users" AD D "first_name" varchar(255) C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:4:in block i n up' C:/Sites/treebook/db/migrate/20121231172750_add_devise_to_users.rb:3:inup' C:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)

There is a typo in the users table. t.string "last_nam" That can't be the culprit though... I'll pull it down and debug locally to see what I can see

Deleted User

thanks.

Pushed some fixes, it should work now!

Deleted User

thanks I have pulled those changes down however i still can't get it working to progress with the course.

I am now getting this error when I click to create a new status

NoMethodError in Statuses#new

Showing C:/Sites/treebook/app/views/statuses/_form.html.erb where line #16 raised:

undefined method `name' for #<Status:0x369faf8> Extracted source (around line #16):

13: 14: <div class="field"> 15: <%= f.label :name %><br /> 16: <%= f.text_field :name %> 17: </div> 18: <div class="field"> 19: <%= f.label :content %><br /> Trace of template inclusion: app/views/statuses/new.html.erb

I ran these commands once I pulled down your updates, i fear i may have screwed somthing up along the way.

rake db:drop:all rake db:create:all rake db:migrate

Check out the schema. There is no name column in the database :)

The Rails docs helped me a lot when I got stuck. Be prepared to do a lot of Googling http://guides.rubyonrails.org/

Deleted User

Thanks Jason, back on track now.

Hey guys I'm having almost the exact same issue. Anytime I try to run rake db:migrate I get the following -

== AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "first_name" varchar(255) /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in initialize' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:innew' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in prepare' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:inexecute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in instrument' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:264:inadd_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:400:in add_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:479:inblock in string' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in each' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:instring' /Users/tharari25/treebook/db/migrate/20130405002233_add_devise_to_users.rb:4:in block in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:inchange_table' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in block in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:inblock in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:inmethod_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:in method_missing' /Users/tharari25/treebook/db/migrate/20130405002233_add_devise_to_users.rb:3:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:370:in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:inblock (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:inmigrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in block in ddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:inddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:ineach' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:inblock (2 levels) in <top (required)>' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in eval' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)

I've tried the suggestions above to no avail :(

Did you manually change something in the user migration file? Double check your Git history.

I did manually change something, not sure what, but never did a git commit. When I did a git pull it said everything was up to date, yet still having this problem.

This is my github repo: https://github.com/tomharari/treebook

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Tom, you'll need to have a user migration first. Try following along with that part of the videos to generate the user model and accompanying migration. Devise can't add to it without that.

Hey, having a problem a the same place. Here's the error I'm getting: https://gist.github.com/shawnacscott/42374c22ddcf7471ed7e

I had an issue initially because I used the 'rails generate devise:install' command when I already had devise installed from another project (d'oh!), and it generated a file that looks exactly like the one for 'user' shown in the video "Generating a User Model," except with 'install' everywhere that 'user' should be. I restored my code from my remote for the previous day and re-did all the devise setup steps (minus the 'rails generate devise:install' command), and it all seemed to be working until this database issue.

You can find my current code with this issue here: https://github.com/shawnacscott/treebook/tree/user_model_generation_issue

Help, please! :)

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Shawna Scott it looks like you're using Rails 4.0. The lessons are using Rails 3.2.13 and that could be causing problems. Can you possibly use 3.2.13 and see if you still have problems?

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

PS: We're working on Rails 4.0 content but it won't be up for a little while.

Sorry I came here to ask this question, but I'm having a similar problem. This is what I'm getting when I try rake db:migrate

rake aborted! You have already activated rake 10.1.0, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this.

Thanks for your help!

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Try running "bundle exec rake db:migrate" instead and see if that works.

Thanks for your answer! I already fix that by doing same rake version changes.