How to generate controller inside namespace in rails
Ruby on-RailsRuby on-Rails-3Ruby on-Rails Problem Overview
I have namespace admin
in controller, and I want to generate a controller inside of the admin
folder. How can i do it with a Rails command?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
Try rails g controller admin/users
if you want a users
controller inside of the admin
namespace. Of course, exchange users
with whatever controller name that you'd like.
Solution 2 - Ruby on-Rails
Use this command..
rails generate controller namespace_name/controller_name
Solution 3 - Ruby on-Rails
If you want to gen it:
rails generate controller namespace_name/controller_name
And If you want to rollback this step using:
rails destroy controller namespace_name/controller_name
Solution 4 - Ruby on-Rails
In your case it will be
$ rails g controller admin/controller_name
If we have an app structure like
-
---controllers
-
--api
-
-v1
and want to generate controller, do:
$ rails g controller api/v1/controller_name
In general
$ rails g controller namespace_1/namespace_2/...../controller_name