Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate controller inside namespace in rails

People also ask

What is namespacing rails?

This is the simple option. When you use namespace , it will prefix the URL path for the specified resources, and try to locate the controller under a module named in the same manner as the namespace.


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.


Use this command..

rails generate controller namespace_name/controller_name


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

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