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
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.
精彩评论