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

Mike Hickman
Mike Hickman
19,817 Points

Ruby on Rails and Devise - Whoops!

So,

The good part - I'm in the middle of building my first RoR app outside of demo projects. I'm stoked, and it's been going great. thumbs up

The bad part - I installed Devise today and accidentally fubar'd some associations. The main function of my app is to add users that are enrolled in our mobile device program at work to a database and store some enrollment data. They are "Users". (you already see where this is going.). While installing Devise, in true rookie fashion, I ran "rails generate devise User" as the model (doh!).

This is no bueno, my friends. Now, when I create a "New User" (for my mobile device users), I get kicked over to a Devise new user registration on submit..saying "e-mail cannot be blank" yada yada.

My question is: What would be the best way to change the current Devise model from 'User' to 'Admin', or something that won't entangle itself in my main User model? Is this even worth doing, or would you scrap your last 2 hours (I'm new, remember) of layout and design work to go back to my git push prior to installing Devise?

Also, if I do figure out how to get back to the state prior to Devise, will I still need to rollback or remove items from the DB?

Route to New Devise User: /users/sign_up (devise/registrations#new)

Route to New User in app: /users/new (users#new)

The paths and prefixes are different, so I was hoping they wouldn't mess with each other, but apparently I'm not so lucky.

If you're still with me, thank you so much for taking the time to read this. Any guidance would be greatly appreciated.

Cheers, Mike

1 Answer

Amy Kang
Amy Kang
17,188 Points

In case you still need help. I found this answer on stackoverflow:

rails destroy devise User

rails generate devise whateveryourmodelnamehere

http://stackoverflow.com/questions/20273584/trying-to-rename-devise-model-name-in-ruby-on-rails

Also, remember to write tests as you build your application and running them after any new features are added so you can catch any errors early.

Mike Hickman
Mike Hickman
19,817 Points

Thanks, Amy. That put me on the right track. Thanks for taking the time to pass along the info.

For anyone that has this issue down the line: I kept getting a bash rails error when attempting to run that command and was never able to figure out why.