shusseina
(shusseina)
August 13, 2009, 5:02pm
1
Imagine I have a model called blog and I then run the following
command to create a controller for it.
ruby script/generate controller Blogs index
At some later point I want to create a 'new' page to submit blogs. Is
there a recommended way for doing this? Should I simply create the
file app/views/blogs/new.html.erb or should I instead run the command
below? Is there any difference?
ruby script/generate controller Blogs new
Thanks
Con
(Con)
August 13, 2009, 5:25pm
2
Imagine I have a model called blog and I then run the following
command to create a controller for it.
ruby script/generate controller Blogs index
At some later point I want to create a ‘new’ page to submit blogs. Is
there a recommended way for doing this? Should I simply create the
file app/views/blogs/new.html.erb or should I instead run the command
below? Is there any difference?
Just use your text editor of choice and create the template file, new.html.erb.
Then you need to remember to add the action, ‘new’, to the blogs_controller.
ruby script/generate controller Blogs new
Now, if you run the command again on the same controller, you should see
something like this:
exists app/controllers/
exists app/helpers/
exists app/views/posts
exists test/functional/
exists test/unit/helpers/
overwrite app/controllers/blogs_controller.rb? (enter “h” for help) [Ynaqdh]
Then you can select ‘n’ if you have modified blogs_controller.rb or ‘Y’ if
have not modified this file. Then you’ll need to add the controller action, ‘new’,
to blogs_controller.rb but you wouldn’t have to create the new.html.erb file.
Good luck,
-Conrad