来自Gem的Rails中未初始化的常量

时间:2015-11-12 05:05:20

标签: ruby-on-rails ruby watir headless

我对rails非常陌生,我正在追逐我的尾巴试图让Rails应用程序在我的服务器上运行。在我的Mac上,一切正常,但是当我在Ubuntu服务器上运行它时,我收到NameError (uninitialized constant Api::V1::TestController::Headless)错误。我已根据其他帖子的建议更新了bundler和相关的gem。我确信Headless在我的gem文件中,是最新的,并且安装正确。我在Watir Webdriver中使用Headless。任何关于可能导致此错误的建议都将不胜感激。

Ruby版本: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'

2 个答案:

答案 0 :(得分:1)

问题是Rails在Headless命名空间下查找Api::V1::TestController常量。

你应该使用::Headless(绝对路径的常量)。

答案 1 :(得分:0)

问题原来是服务器所有权。因为我在自己的帐户下运行bundle install,所以我的案例中的用户没有宝石的所有权。 rails用户chmod处理了这个问题!