我继承了一个 Rails 项目并被要求对其进行更新,因此我将 Rails 2.2.2 项目迁移到 Rails 3.2。
我浏览了一些迁移教程并运行了 rails 升级脚本,当默认 /public/index.html 存在时,它可以正常加载。
然后我继续删除 /public/index.html,因此应用程序将指向 routes.rb 中指示的文件,然后我得到:
LoadError (Expected /var/www/vendor_sandbox/app/controllers/application.rb to define Application):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/home_controller.rb:1:in `<top (required)>'
导致错误的文件来自原始 Rails 2.2.2 代码库。我离开它是因为在迁移文档中没有任何迹象表明我正在阅读提到删除它,但显然有问题。
我觉得奇怪的是,我现在在 /config 中有一个 Rails 3 版本的 application.rb,在 /app/controllers/ 中有一个 application.rb
不确定如何处理 /app/controllers/application.rb。
以下是提到的文件:
 #### /app/controllers/application.rb
class ApplicationController < ActionController::Base
 helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => 'mysecretkey'
# See ActionController::Base for details 
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password"). 
# filter_parameter_logging :password
def authenticate
  return true if session[:user_id].to_i > 0
  session[:after_login] = params
  redirect_to :controller => "login"
  return false
end
def authenticate_admin
  user = User.find(session[:user_id])
  @nav = [{:title => "Home", :action => {:controller => "home"}}]
  return true if user and user.is_admin?
  redirect_to :controller => "login"
  return false
end
def clean_date_for_4D date
  return "00/00/00" if !date or date == ""
  return date.strftime("%m/%d/%Y") if date.class.to_s == "Date"
  return Date.parse(date).strftime("%m/%d/%Y") # assume it's a string
end
def pad text, length=20
  while text.length < length do
    text = text + " "
   end
  return text
 end
end
 #### /config/routes.rb
 VendorSandbox::Application.routes.draw do
 match '/' => 'home#index'
 match '/:controller(/:action(/:id))'
end
#### /config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module VendorSandbox
  class Application < Rails::Application
    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"
    # Configure sensitive parameters which will be filtered from the   log file.
  config.filter_parameters += [:password]
    # Enable escaping HTML in JSON.
    config.active_support.escape_html_entities_in_json = true
    config.active_record.whitelist_attributes = true
    # Enable the asset pipeline
    config.assets.enabled = true
    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
    # Session key
     config.session_store(:cookie_store, {:key => '_vendor_sandbox_session', :secret => 'secretkey'
    # Time zone
   config.time_zone = 'Central Time (US & Canada)' #'UTC' # Had to change this to keep created_at from being 4 hours in advance!
 config.active_record.default_timezone = 'Central Time (US & Canada)'
  end
end