0

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 コード ベースのものです。私が読んでいた移行ドキュメントには、それを削除することについて言及していたという兆候がなかったので、私はそれを残しましたが、明らかに何かが間違っています.

Rails 3 バージョンの application.rb が /config にあり、application.rb が /app/controllers/ にあるのは奇妙です。

/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
4

2 に答える 2

1

に名前を変更しようとapp/controllers/application.rbしていますapplication_controller.rb

_controllerRails は、コントローラーに接尾辞を付けて名前を付けることを期待していると思いapplication.rbますが、コントローラーフォルダーにある はその規則に従っていません。

于 2013-02-22T14:44:07.323 に答える
0

@Zajnの回答にコメントしたかったのですが、必要な「50の評判」がありません。

参考までに、Rails 2.3 でapp/controllers/application.rbに名前が変更されました。application_controller.rb

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

于 2015-02-06T19:33:35.830 に答える