0
내 응용 프로그램에 API로 사용하려는 몇 가지 컨트롤러가 있습니다. 이 API에서는 버전 관리를 사용해야합니다. 이를 사용하여 내 routes.rb
난`에모델에서 모듈을 무시하십시오.
:
require 'api_constraints'
(...)
scope '/:target/:version', :module => :api, :constraints => { :version => /[0-z\.]+/ } , :defaults => { :format => 'json' } do
scope :module => :v1, :constraints => ApiConstraints.new(:version => 1, :default => true) do
match '/list' => 'sample#list'
end
end
내 api_constraints.rb
:에
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
def matches?(req)
@default || req.headers['Accept'].include?("application/waytaxi.api.v#{@version}")
end
def self.version
@version
end
end
내 SampleController.rb
:
module Api
module V1
class SampleController < ApiBaseController
def list
render json: Model.find_by_id(params[:id])
end
end
end
end
ApiBaseController
:
module Api
class ApiBaseController < ApplicationController
before_filter :authenticate
skip_before_filter :verify_authenticity_token
private
def authenticate
# if params[:target] == "ios"
# render :json => {status: 404}
# return false
# end
end
end
end
문제는 : 내가 사용하는 경우
uninitialized constant Api::V1::SampleController::Model
: ::Model
내가이 오류가 난 시도 할 때마다
내가이 오류가 Model
전화 :
uninitialized constant Model
그리고 네, 제 데이터베이스에는이 모델이 있습니다. 내가 밖에있는 Model.all
을 사용하면 나는 물건을 얻는다.
P.S : 나는 내 문제 발견 레일 3.2.8