hellomello
hellomello

Reputation: 8587

Ruby on Rails generating controller with existing folder

I'm really new at this and I don't want to mess up my current application. I'm currently working on HTML/CSS stuff but I have a little understanding as to how to get things working.

I created a new controller by just doing

rails generate controller sign_up

I've created a index file (index.html.erb) inside sign_up folder from rails that automatically generated. Now I wanted to add more files, can I just add more files by typing in

rails generate controller sign_up send_page more_page other_pages

Will send_page, more_page, other_pages be automatically combined into the existing sign_up folder? Is this the correct way of adding pages if I want rails to add other files automatically? I just want it to ruin what I have so far so I don't want to try it for myself because I'm still really new to this,

Thanks!

Upvotes: 0

Views: 1060

Answers (2)

vdaubry
vdaubry

Reputation: 11439

To answer your question :

New files will be added to the existing folder but existing files will not be merged, you'll have to resolve the conflict by choosing between old and new files.

It seems to me you're trying to use generators for every action you need in your app :

Scaffolding is great to have a sample structure, but as soon as you start building your controller for real you need to move away from it : extend the controllers, models and views by hand. It's the only way you'll start to really understand how things are working.

Upvotes: 2

Jim Stewart
Jim Stewart

Reputation: 17323

If you run the generator again, it's going to complain about conflicts with existing files. Then you'll have to choose to overwrite (losing your existing changes to e.g. the controller), or not (in which case you won't get the new auto-generated methods, etc.).

You can just create a new controller action and a new view for each additional page you want to add (and a unit test, of course!). If you're using non-standard/non-restful action names, you'll also have to edit config/routes.rb to route them.

Looking at the names in your example, and your reference to "pages", I suspect what you really may want to do is create separate controllers for send_page and more_page. If that's the case, you'd run the generator separately for each new controller.

Upvotes: 1

Related Questions