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

問題は:

電話しようとするたびModelに、このエラーが発生します:

uninitialized constant Api::V1::SampleController::Model

私が使用する場合:::Model私はこのエラーが発生します:

uninitialized constant Model

はい、データベースにこのモデルがあります。Model.all外部で使用するSampleControllerと、オブジェクトを取得します。

PS:レール3.2.8を使用しています

4

1 に答える 1

0

私の問題を見つけました。

私のモデルは複数形で、コントローラーでは単数形で呼び出していました

于 2012-10-25T13:36:44.737 に答える