How can I generate a controller with mutiple levels of namespaces like:
/api/v1/users
This fails:
rails g controller api/v1/users
Error:
`namespace': wrong number of arguments (0 for 1..2) (ArgumentError)
rails g controller 'api/v1/users'
will generate the class Api::V1::UsersController < ApplicationController in app/controllers/api/v1 directory.
Note this creates the controller in the Api::V1:: namespace, which is different than a controller defined thusly:
module Api
module V1
class Users
But you could always just change that manually after it's generated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With