Ruby on rails Rails API问题
我在Mac OS Mavericks上,使用Ruby 2.0.0p353 在遵循“”railscast在我的网站上创建restful API时,我遇到了以下错误:Ruby on rails Rails API问题,ruby-on-rails,ruby,Ruby On Rails,Ruby,我在Mac OS Mavericks上,使用Ruby 2.0.0p353 在遵循“”railscast在我的网站上创建restful API时,我遇到了以下错误: RuntimeError in Api::V1::SurveysController#index Circular dependency detected while autoloading constant Api::V1::SurveysController Rails.root: /Users/thomashammond89/
RuntimeError in Api::V1::SurveysController#index
Circular dependency detected while autoloading constant Api::V1::SurveysController
Rails.root: /Users/thomashammond89/SurveyMe
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"format"=>"json"}
以下是我的调查\u controller
,可在controllers/api/v1下找到:
module Api
module V1
class ProductsController < ApplicationController
before_filter :restrict_access
respond_to :json
def index
respond_with Survey.all
end
def show
respond_with Survey.find(params[:id])
end
def create
respond_with Survey.create(params[:survey])
end
def update
respond_with Survey.update(params[:id], params[:survey])
end
def destroy
respond_with Survey.destroy(params[:id])
end
def restrict_access
api_key = ApiKey.find_by_access_token(params[:access_token])
head :unauthorized unless api_key
end
end
end
end
我的路线是:
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
resources :surveys
end
end
你知道我做错了什么,或者错误是从哪里来的吗?我尝试在“”之后将Rails版本从4.0.1更改为4.0.0
“”指的是他有两个相同的控制器,一个在api文件夹下。我还有两个调查_controllers.rb。这可能是问题的根源吗?如果是这样,有人知道我应该如何在api文件夹下设置控制器,以便显示我的调查吗?railscast让我创建第二个控制器。生成访问令牌功能应为
def generate_access_token
begin
self.access_token = SecureRandom.hex
end while self.class.exists?(access_token: access_token)
end
如何有两个
测量\u控制器.rb
?OSX文件系统不允许在一个目录中有重复的文件名,其中一个在我的controllers文件夹中。另一个位于api/v1文件夹中,该文件夹本身位于控制器文件夹中。跟着火车走你有没有试着用正确的名字称呼你的测量控制员?目前,它被定义为执行此操作的ProductsController
。真不敢相信我错过了……作为写问题或任何超链接文本时的提示,在写锚文本时不要使用“this”或“here”。取而代之的是,使用描述性的文本,帮助指示链接将带读者到哪里。有关详细信息,请参阅“HTML技术用于Web内容可访问性指南1.0”中的“”和“”。
def generate_access_token
begin
self.access_token = SecureRandom.hex
end while self.class.exists?(access_token: access_token)
end