There is any way to generate a new action and view to an existing controller ? I've tried to do following to an existing controller
$ script/rails generate controller posts view
where view is the new action which I want to add to controller. I know it's trivial to do it by hand but I'm wondering is something which I don't know or I dream to much.
thanks -rr
To generate a controller and optionally its actions, do the following: Press Ctrl twice and start typing rails g controller. Select rails g controller and press Enter . In the invoked Add New Controller dialog, specify the controller name.
Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
It's so trivial, there's just no generator for it. At best you could copy your controller into your clipboard, and then regenerate the complete scaffold (but answer no to the views that you don't want modified) and it will add the view, and overwrite your controller... and then paste your own code back... but really, by that point it would have been easier to just add them by hand.
The only time I might regenerate is early on when I didn't have my schema right and I want to let the generator fix my form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With