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

ruby on rails generate

Hello,

In the ruby course, we generate the user model in the section "Generating the User Model" by doing the command:

rails generate devise:user

we then go to

localhost:3000/users/sign_up 

and we can see a registration form.

On the next lesson called "Generating the Devise Views" we run the command rails generate devise:views

we then modify the generated view by adding fields.

Was the the html for the signup file generated with devise:user or devise:views? I guess I'm a bit confused because localhost:3000/users/sign_up was already accessible and the html files seem to have been generated with

rails generate devise:views

2 Answers

Jim Hoskins
STAFF
Jim Hoskins
Treehouse Guest Teacher

Hi Nano,

Yes, the HTML was added to your app/views directory by

rails generate devise:views

The way rails and its plugins work, like devise, is the plugin can provide its own code. That code, like the plugin's views, can live within the directory the plugin is installed in. Rails will look in your app directory for code and views, but it will also fall back to the directories of your various plugins. That's great for keeping your code separated from the plugin code, but if you want to customize it, it becomes a problem.

When you generated the views, it copied the view files from the plugin dir to your app dir. Your app directory is highest priority, so these files can be customized. If you were to delete these views, devise would still work, but it would fall back to the defaults in the plugin's directory.

Hope that makes sense.

Hi Jim. That makes sense thanks for clearing this up!

If I understand correctly the sign up page was accessible before generating views because rails fell back on the devise plugin and showed the default form. When we customized it, it used the views that were generated and moved to the app folder.