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
Dennis Witnauer
12,336 PointsHow do I delete a user from db in Ruby on Rails?
While following along with the Ruby simple application, I inadvertently created a couple of users without names and/or email addresses, so now I get 'nil' errors on most pages. How do I delete a user from the database?
4 Answers
Aimee Knight
9,701 Pointsrake db:reset is your best friend. In simple terms it will delete your database then rebuild it without users (or attributes) all in one command.
Dennis Witnauer
12,336 PointsThank you, Aimee. That worked perfectly...best friend, indeed.
Derrick Mull
18,518 PointsIn the rails console you can use
User.delete_all
The
rake db:reset
Is a bit overkill. It drops the entire database and recreates it via the schema.rb. Which is not the same as running the migrations.
Dennis Witnauer
12,336 PointsThank you, Derrick. Great to know. Cheers.