Rails 3迁移和application.rb

时间:2013-02-22 14:30:11

标签: ruby-on-rails-3 migration

我继承了一个Rails项目,并被要求更新它,所以我将Rails 2.2.2项目迁移到Rails 3.2。

我经历了一些迁移教程并运行了rails升级脚本,当默认的/public/index.html存在时,它会正常加载。

然后我继续删除了/public/index.html,因此app会指向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

2 个答案:

答案 0 :(得分:1)

尝试将app/controllers/application.rb重命名为application_controller.rb

我认为Rails期望您的控制器以_controller后缀命名,而您在控制器文件夹中的application.rb不符合该约定。

答案 1 :(得分:0)

我想对@Zajn回答发表评论,但我没有得到所需的&#34; 50声誉&#34;。

仅供参考,app/controllers/application.rb已在Rails 2.3中重命名为application_controller.rb

http://guides.rubyonrails.org/2_3_release_notes.html#application-controller-renamed