How to generate controller inside namespace in rails

Ruby on-RailsRuby on-Rails-3

Ruby 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2088247View Question on Stackoverflow
Solution 1 - Ruby on-RailsChris PetersView Answer on Stackoverflow
Solution 2 - Ruby on-RailsRamiz RajaView Answer on Stackoverflow
Solution 3 - Ruby on-RailsThienSuBSView Answer on Stackoverflow
Solution 4 - Ruby on-RailsManishView Answer on Stackoverflow