with tutorial rails practices creating crear best ruby-on-rails web-services api ruby-on-rails-4 routes

ruby on rails - tutorial - Crear API en Rails 4-Constante no inicializada Api:: V1:: UsersController



rails api serializer (1)

si tienes este camino:

MyProject> app> controladores> api> v1> usuarios

El controlador debe ser de class Api::V1::Users::UsersController si esto:

MyProject> aplicación> controladores> api> v1> users_controller.rb

entonces class Api::V1::UsersController

Para el nombre de la API::V1::UsersController en API::V1::UsersController lugar Api::V1::Users::UsersController use inflectors:

en config/initializers/inflections.rb

ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym ''API'' end

Para un proyecto personal, me gustaría crear un servicio web tranquilo en Rails 4.

Entonces, creé mi primer proyecto usando rails-api y rails-api el siguiente código:

routes.rb en el directorio MyProject> config

MyProject::Application.routes.draw do namespace :api, defaults: {format: ''json''} do namespace :v1 do resources :users end end end

users_controller.rb en MyProject> app> controladores> api> v1> directorio de usuarios

module Api module V1 class UsersController < ApplicationController def index end def create end def show end def update end def delete end end end end

Cuando inicio el servidor de rieles con los rails s línea de comandos y voy a esta URL: http://localhost:3000/api/v1/users/show Tengo este error:

constante no inicializada Api :: V1 :: UsersController

Rails.root: / Users / Jean / Development / MyProject

Seguimiento de la aplicación | Seguimiento del marco | Full Trace activesupport (4.0.4) lib / active_support / inflector / methods.rb: 228: en const_get'' activesupport (4.0.4) lib/active_support/inflector/methods.rb:228:in bloque en constantize'' activesupport (4.0. 4) lib / active_support / inflector / methods.rb: 224: en each'' activesupport (4.0.4) lib/active_support/inflector/methods.rb:224:in inject'' activesupport (4.0.4) lib / active_support / inflector / methods.rb: 224: en constantize'' actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:76:in controller_reference'' actionpack (4.0.4) lib / action_dispatch / routing / route_set.rb: 66: en controller'' actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:44:in llamada'' actionpack (4.0.4) lib / action_dispatch / journey / router.rb: 71: en el block in call'' actionpack (4.0.4) lib/action_dispatch/journey/router.rb:59:in cada ''actionpack (4.0.4) lib / action_dispatch / journey / router.rb: 59: in call'' actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:674:in llamada ''rack (1.5.2) lib / rack / etag.rb: 23: en la call'' rack (1.5.2) lib/rack/conditionalget.rb:25:in call'' rack (1.5.2) lib/rack/conditionalget.rb:25:in llamada ''rack (1.5.2) lib / rack / head.rb: 11: en la call'' actionpack (4.0.4) lib/action_dispatch/middleware/params_parser.rb:27:in call ''activerecord (4.0.4) lib / active_record / query_cache.rb: 36: en la call'' activerecord (4.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in call ''activerecord (4.0.4) ) lib / active_record / migration.rb: 373: en la call'' actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:29:in bloque en la llamada'' activesupport (4.0.4) lib / active_support / callbacks.rb : 373: en _run__4323212420903942114__call__callbacks'' activesupport (4.0.4) lib/active_support/callbacks.rb:80:in run_callbacks'' actionpack (4.0.4) lib / action_dispatch / middleware / callbacks.rb: 27: in call'' actionpack (4.0.4) lib/action_dispatch/middleware/reloader.rb:64:in llamada ''actionpack (4.0.4) lib / action_dispatch / middleware / remote_ip.rb: 76: en la call'' actionpack (4.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in llamada ''actionpack (4.0.4) lib / action_dispatch / mi ddleware / show_exceptions.rb: 30: in call'' railties (4.0.4) lib/rails/rack/logger.rb:38:in call_app'' railties (4.0.4) lib / rails / rack / logger.rb: 20: en el block in call'' activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in bloque en la etiqueta'' activesupport (4.0.4) lib / active_support / tagged_logging.rb: 26: en la tagged'' activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in ''railties etiquetados (4.0.4) lib / rails / rack / logger.rb: 20: in call'' actionpack (4.0.4) lib/action_dispatch/middleware/request_id.rb:21:in call ''rack (1.5.2) lib / rack / runtime.rb: 17: en la call'' activesupport (4.0.4) lib/active_support/cache/strategy/local_cache.rb:83:in call ''rack ( 1.5.2) lib / rack / lock.rb: 17: en la call'' actionpack (4.0.4) lib/action_dispatch/middleware/static.rb:64:in call'' railties (4.0.4) lib / rails / engine. rb: 511: in call'' railties (4.0.4) lib/rails/application.rb:97:in llamada'' rack (1.5.2) lib / rack / lock.rb: 17: en call'' rack (1.5.2) lib/rack/content_length.rb:14:in call ''rack (1.5.2) lib / rack / handler / webrick.rb: 60: en service'' /Users/Jean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in service'' /Users/Jean/.rvm/rubies/ ruby-2.1.2 / lib / ruby ​​/ 2.1.0 / webrick / httpserver.rb: 94: en run'' /Users/Jean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in block en start_thread ''

Encontré muchas publicaciones en Stackoverflow con el mismo error pero las respuestas no me ayudaron a resolver mi problema.

Gracias !