rails:3805
From: dezawa <dezawa@a...>
Date: Thu, 13 Sep 2012 16:08:53 +0900
Subject: [rails:3805] rails 3.2 の autoload_paths
出沢です
Rails3.2の勉強を、といままでRails 2.3 で動かしていたアプリの
移行を行っていて、はまっています。
いままで restful-authentication を使っていたので、
rails3-restful-authentication を使うことにしました。
Gemfile に
gem "rails3-restful-authentication", "~> 3.0.1"
を追加し、bundle し、
rails g authenticated user sessions --stateful
を行うと、model,view,controller,unit test,function test ができ、
lib に authenticated_system.rb authenticated_test_helper.rb が
作られました。
ここで、
rake test:units TEST=test/unit/user_test.rb
を行うと
・・・/app/models/user.rb:4:in `<class:User>': uninitialized constant
User::Authentication (NameError)
のエラーとなります。
include Authentication
の失敗です。
Rails.root以下には Authentication の定義は見つかりませんでした。
find . -name "*rb" | xargs grep Authentication
gemで入れてるのだから、と探すと
/usr/lib/ruby/gems/1.9.1/gems/rails3-restful-authentication-3.0.1/lib/
に authentication.rb があり、これとその下の subdir authentication に
models/user.rb がinclude している
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
include Authorization::StatefulRoles
がありました。
さて、
Gemfile で指定されたgemは autoload の対象にならないのでしょうか?
autoloadの対象にするにはどうしたらよいでしょうか。
# controllerがinclude している AuthenticatedSystem のためには
# config/application.rb: に
# config.autoload_paths += %W(#{config.root}/lib)
#を追加しています。
# app/lib に移す方が Rails3 的なのでしょうか
よろしくお願いします。
--
ML: rails@r...
使い方: http://QuickML.com/
-> 3805 2012-09-13 09:08 [dezawa@a... ] rails 3.2 の autoload_paths 3806 2012-09-13 09:58 ┗[netwillnet@g... ] 3807 2012-09-13 12:13 ┣[dezawa@a... ] 3819 2012-09-21 00:53 ┗[dezawa@a... ]