开发者

Is calling rails g controller user multiple times safe?

开发者 https://www.devze.com 2023-02-09 17:31 出处:网络
If I call rails g controller user multiple times to add actions, is this safe? e.g. I did \'rails g controller user index\' but now I want t开发者_如何转开发o create more actions?

If I call

rails g controller user

multiple times to add actions, is this safe?

e.g. I did 'rails g controller user index' but now I want t开发者_如何转开发o create more actions?

btw, how can I create all REST based actions automatically?


yesh, safe. See rails g scaffold for generating REST actions automatically, including the model and views and tests.

Note that you can also pass a option --pretend when running the generator so that it shows you what files will be created, but does not actually create the files.


unless your generating a scaffold then you're probably off better doing it manually anyhow and not using the generator.

In your routes.rb make sure you've got

resources :user

so now all 7 restful routes will exist (you can check from terminal via rake routes) and then just add the methods to your controller as you need them, index, show, new, edit, create, update, delete. Don't forget if you don't want a route to exist you can omit them

resources :user, :except => [:index]

and vice versa if you only want a few methods

resources :user, :only => [:index, :create]
0

精彩评论

暂无评论...
验证码 换一张
取 消