2015-11-12 45 views
2

我对Rails相当陌生,正在追逐我的尾巴,试图让Rails应用程序在我的服务器上运行。本地在我的Mac上,一切工作正常,但是当我在Ubuntu服务器上运行它时,出现NameError (uninitialized constant Api::V1::TestController::Headless)错误。我已经更新了捆绑商和其他职位中建议的相关宝石。我确信Headless是我的宝石文件,是最新的,并且安装正确。我正在和Watir Webdriver一起使用Headless。任何有关可能导致此错误的建议将不胜感激。来自Gem的Rails中未初始化的常量

红宝石版本:2.2.3

有问题的控制器:

class Api::V1::TestController < ApplicationController 
    respond_to :json 

    def index 
    respond_with "test controller" 
    end 

    def create 

    event_submit(params[:json_event]) 

    respond_to do |format| 
     if (@log.present?) 
     format.json { render text: "Log: " + @log } 
     else 
     format.json { render text: "Error, no log" } 
     end 
    end 

    end 

    def nul_check(param) 
    param ||= "none" 
    return param 
    end 


    def event_submit(params) 

    @log = "" 

    #initialize the log 
    @log = "" 
    #set the browser that we will use to chrome for testing 
    #use headless 
    headless = Headless.new 
    headless.start 

    browser = Watir::browser.start 'www.google.com' 

    @log += browser.title 

    end 

end 

的Gemfile中:

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.4' 
# Use postgresql as the database for Active Record 
gem 'pg' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

#Api gems 
gem 'active_model_serializers' 
gem 'deathbycaptcha' 
gem 'rspec' 
gem 'responders', '~> 2.0' 


#Driver gems 
gem 'watir-extensions-element-screenshot' 
gem 'selenium-webdriver' 
gem 'chromedriver-helper' 
gem 'headless' 
gem 'nokogiri' 
gem 'watir-webdriver' 

group :development, :test do 
    gem 'sqlite3' 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug' 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 


gem 'unicorn' 
+1

如果不是'无头'你把'::无头'(注意双冒号),它是否工作? – AmitA

+1

是否在控制器顶部放置'require'headless''有帮助? –

+0

使用:: Headless没有明显的效果。我犯了同样的错误。 在控制器的顶部添加'require'headless''会导致网关超时。它不会向错误日志添加任何内容,并且在本地执行此操作时不会产生任何影响。我与Unicorn/Nginx断绝关系 – Paige

回答

0

问题原来是服务器所有权。用户,在我的情况下,铁轨没有宝石的所有权,因为我已经运行我自己的帐户bundle install。一个chmod为rails用户照顾的问题!

1

的问题是,Rails将在Headless常数Api::V1::TestController命名空间下。

您应该使用::Headless(常数的绝对路径类型)。

+0

我认为Ruby应该从Api :: V1 :: TestController中解析顶级常量'Headless'。也许我不了解不同Ruby实现之间的行为差​​异。通常,仅当给定的常量名称出现在多个名称空间中并且不能从当前上下文中解析为期望的实例时,才需要为常量加前缀。 –

相关问题