Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a controller with a namespace that has 2 levels?

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)
like image 396
Blankman Avatar asked Apr 13 '14 17:04

Blankman


1 Answers

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.

like image 96
Doug R Avatar answered Nov 15 '22 01:11

Doug R