Yourub Gem的NameError(未初始化的常量)

时间:2016-08-26 20:29:28

标签: ruby-on-rails youtube-data-api

当我使用Yourub gem配置搜索youtube视频搜索时,服务器控制台会返回以下错误消息:

Completed 500 Internal Server Error in 7ms

NameError (uninitialized constant ExploreController::Yourub):
  app/controllers/explore_controller.rb:18:in `search'

在explore_controller文件中,我们可以找到:

class ExploreController < ApplicationController
  def index
    ...
  end
  def search
    if params[:queryType] == "users"
      ...
    elsif params[:queryType] == "tracks"
      client = Yourub::Client.new
      client.search(query: params[:queryField]) do |v|
        puts v
      end
      return redirect_to('/explore')
    else
      return redirect_to('/explore')
    end
  end
end
  

此处还添加了我的yourub.yml文件:

yourub_defaults: &yourub_defaults
  developer_key: 'apiKey'
  youtube_api_service_name: 'youtube'
  youtube_api_version: 'v3'
  application_name: "apiAplicationName"
  application_version: "0.1"
  log_level: WARN

development:
  <<: *yourub_defaults

production:
  <<: *yourub_defaults

test:
  <<: *yourub_defaults

1 个答案:

答案 0 :(得分:1)

重新启动服务器。这应该可以解决问题。