Rails:从开发变为生产导致NameError未初始化的常量

时间:2014-10-19 16:44:02

标签: ruby-on-rails-4 deployment passenger development-environment production-environment

我的应用程序在我的mac笔记本电脑上的开发环境(WEBrick 1.3.1)中运行。我通过capistrano将它部署到运行nginx&的Ubuntu服务器上乘客突然间我正在接受

  

SmsController中的NameError#send_text_message:未初始化的常量   SmsController :: ******中国

。这是一个截图:

enter image description here

显然,PhoneNumber类(app / models / phone_number.rb)未被识别。以下是该类的代码:

class PhoneNumber
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :pnumber

  validates :pnumber, presence: true 
  validates :pnumber, numericality: true

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end
end

以下是引发错误的控制器的代码:

class SmsController < ApplicationController
  def send_text_message
    phone = PhoneNumber.new(pnumber: params[:phone]) 
    logger.info "phone as submitted by the webform (params[:phone]) = " + params[:phone]
    if phone.valid?
      # code that sends a sms message..
      flash[:success] = "Message has been sent!"
      redirect_to :back
    else
      flash[:warning] = "This is not a valid mobile number" 
      redirect_to :back
    end
  end
end

我需要做些什么才能让这项工作投入生产?

==编辑:我在生产环境下使用相同的堆栈(nginx,乘客)在我的mac上本地运行它,我没有收到错误消息。所以它似乎必须是我的Ubuntu VPS上的安装特有的东西。我重新启动了nginx,但它没有改变任何东西。我真的很难过 - 理论上这个怪怪不应该发生。

== EDIT2:根据@rossta的要求,这里是config / application.rb的内容:

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Appmate
  class Application < Rails::Application
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.
end
end

以下是config / environments / production.rb的内容:

Appmate::Application.configure do
config.cache_classes = true   a
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local       = true # changed to help with debugging, TODO: change back to false once in production
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end

1 个答案:

答案 0 :(得分:0)

我找到了罪魁祸首 - 我似乎没有向我的git存储库提交控制器和模型文件。所以一切都与那一点有关。杜!

@rossta:谢谢你的帮助!那流浪的&#39; a&#39;这是我在将代码复制到SO帖子时必须添加的内容,但是您的问题让我查看了我的git存储库 - 这就是我找到已更改但未提交文件的方式。