0

我的應用程序在我的Mac筆記本電腦上的開發環境(WEBrick 1.3.1)中工作。我通過Capistrano的部署它到Ubuntu的服務器上運行Nginx的&乘客突然我得到的SmsController#send_text_messageRails:從開發變爲生產導致NameError未初始化常量

NameError:未初始化不斷 SmsController :: ******中國

。下面是截圖:

enter image description here

顯然,******中國類(應用程序/模型/ 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 /環境/ 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 
+0

你可以分享'config/application.rb'和'config/environments/production.rb'的內容嗎? – rossta 2014-10-20 04:42:30

+0

@rossta:我剛發佈了它。 – Nick 2014-10-20 11:25:26

+0

「PhoneNumber」所在的文件路徑是什麼? – rossta 2014-10-20 15:40:24

回答

0

我發現的罪魁禍首 - 我似乎還沒有向我的git存儲庫提交控制器和模型文件。所以一切工作都離開那個位子。咄!

@rossta:謝謝你的幫助!這個流浪'a'是我在將代碼複製到SO文章中時必須添加的,但是您的問題讓我看到了我的git存儲庫 - 這就是我如何找到已更改但未提交的文件。

相關問題