Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add new action and view with script/rails generate?

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

like image 657
ruslander Avatar asked Aug 28 '11 01:08

ruslander


People also ask

How do I create a controller in Rails?

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.

What are partials in Rails?

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.


1 Answers

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.

like image 118
DGM Avatar answered Sep 29 '22 13:09

DGM