/app
/controllers
/users
profiles_controller.rb
users_controller.rb
/models
/user
/profile.rb
user.rb
#/app/models/user.rb
class User < ActiveRecord::Base
has_one :profile, class_name: "User::Profile"
end
#/app/models/user/profile.rb
class User::Profile < ActiveRecord::Base
belongs_to :user
end
#/app/controllers/users/profiles_controller.rb
class Users::ProfilesController < ApplicationController
layout "layouts/profile"
end
#/app/controllers/users/users_controller.rb
class Users::UsersController < Users::ProfilesController
def show
@user = User.find(params[:id])
end
end
コンソールでプロファイル モデルにアクセスするときに、エラーはありません。
vagrant@lucid32:/vagrant$ レール c 開発環境のロード (Rails 3.2.11) irb(メイン):001:0> u = User.new => <#User id: nil, created_at: nil, updated_at: nil, username: nil, crypted_password: nil, password_salt: nil, persistence_token: nil, perishable_token: nil, activate_token: nil, login_count: 0, failed_login_count: 0, アクティブ化: false, 禁止: false, last_request_at: nil, last_login_at: nil, current_login_at: nil, last_login_ip: nil, current_login_ip: nil> irb (メイン):002:0> u.build_profile (0.5ms) BEGIN (0.4ms) コミット => <#User::Profile id: nil, user_id: nil, person: nil, company: nil, company_position: nil, info: nil, birthday: nil, created_at: nil, updated_at: nil>
user/users#show にアクセスしようとすると、次のエラーが発生しました。
ユーザーの LoadError::UsersController#show /vagrant/app/models/user/profile.rb がプロファイルを定義することを期待 activesupport (3.2.11) lib/active_support/dependencies.rb:503:in `load_missing_constant' activesupport (3.2.11) lib/active_support/dependencies.rb:192:in `ブロック in const_missing' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `each' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `const_missing' activesupport (3.2.11) lib/active_support/dependencies.rb:514:in `load_missing_constant' activesupport (3.2.11) lib/active_support/dependencies.rb:192:in `ブロック in const_missing' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `each' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `const_missing' activesupport (3.2.11) lib/active_support/inflector/methods.rb:230:in `ブロックイン定数化' activesupport (3.2.11) lib/active_support/inflector/methods.rb:229:in `each' activesupport (3.2.11) lib/active_support/inflector/methods.rb:229:in `定数化' activesupport (3.2.11) lib/active_support/inflector/methods.rb:260:in `safe_constantize' activesupport (3.2.11) lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize' actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model' actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults' actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:133:in '継承' actionpack (3.2.11) lib/abstract_controller/railties/routes_helpers.rb:7:in `ブロック (2 レベル) in with' actionpack (3.2.11) lib/action_controller/railties/paths.rb:7:in `ブロック (2 レベル) in with' app/controllers/users/profiles_controller.rb:1:in `' activesupport (3.2.11) lib/active_support/dependencies.rb:469:in `load' activesupport (3.2.11) lib/active_support/dependencies.rb:469:in `block in load_file' activesupport (3.2.11) lib/active_support/dependencies.rb:639:in `new_constants_in' activesupport (3.2.11) lib/active_support/dependencies.rb:468:in `load_file' activesupport (3.2.11) lib/active_support/dependencies.rb:353:in `require_or_load' activesupport (3.2.11) lib/active_support/dependencies.rb:502:in `load_missing_constant' activesupport (3.2.11) lib/active_support/dependencies.rb:192:in `ブロック in const_missing' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `each' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `const_missing' app/controllers/users/users_controller.rb:1:in `' activesupport (3.2.11) lib/active_support/dependencies.rb:469:in `load' activesupport (3.2.11) lib/active_support/dependencies.rb:469:in `block in load_file' activesupport (3.2.11) lib/active_support/dependencies.rb:639:in `new_constants_in' activesupport (3.2.11) lib/active_support/dependencies.rb:468:in `load_file' activesupport (3.2.11) lib/active_support/dependencies.rb:353:in `require_or_load' activesupport (3.2.11) lib/active_support/dependencies.rb:502:in `load_missing_constant' activesupport (3.2.11) lib/active_support/dependencies.rb:192:in `ブロック in const_missing' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `each' activesupport (3.2.11) lib/active_support/dependencies.rb:190:in `const_missing' activesupport (3.2.11) lib/active_support/inflector/methods.rb:230:in `ブロックイン定数化' activesupport (3.2.11) lib/active_support/inflector/methods.rb:229:in `each' activesupport (3.2.11) lib/active_support/inflector/methods.rb:229:in `定数化' activesupport (3.2.11) lib/active_support/dependencies.rb:554:in `get' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:69:in `controller_reference' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:54:in `コントローラー' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:32:in `call' ジャーニー (1.0.4) lib/journey/router.rb:68:in `block in call' ジャーニー (1.0.4) lib/journey/router.rb:56:in `each' ジャーニー (1.0.4) lib/journey/router.rb:56:in `call' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' ラック (1.4.5) lib/rack/etag.rb:23:in `call' ラック (1.4.5) lib/rack/conditionalget.rb:25:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call' ラック (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' ラック (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call' activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call' activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__1047939203__call__223494719__callbacks' activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:「タグ付き」 railties (3.2.11) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call' ラック (1.4.5) lib/rack/methodoverride.rb:21:in `call' ラック (1.4.5) lib/rack/runtime.rb:17:in `call' activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call' ラック (1.4.5) lib/rack/lock.rb:15:in `call' actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call' railties (3.2.11) lib/rails/engine.rb:479:in `call' railties (3.2.11) lib/rails/application.rb:223:in `call' railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing' ラック (1.4.5) lib/rack/lint.rb:48:in `_call' ラック (1.4.5) lib/rack/lint.rb:36:in `call' ラック (1.4.5) lib/rack/showexceptions.rb:24:in `call' ラック (1.4.5) lib/rack/commonlogger.rb:33:in `call' ラック (1.4.5) lib/rack/chunked.rb:43:in `call' ラック (1.4.5) lib/rack/content_length.rb:14:in `call' ユニコーン (4.6.2) lib/unicorn/http_server.rb:552:in `process_client' ユニコーン (4.6.2) lib/unicorn/http_server.rb:632:in `worker_loop' ユニコーン (4.6.2) lib/unicorn/http_server.rb:500:in `spawn_missing_workers' ユニコーン (4.6.2) lib/unicorn/http_server.rb:142:in `start' ユニコーン (4.6.2) bin/unicorn:126:in `' /usr/local/rbenv/versions/1.9.3-p194/bin/unicorn:23: in `load' /usr/local/rbenv/versions/1.9.3-p194/bin/unicorn:23:in `'
正確な理由はわかりませんが、私の意見は次のとおりです。
メソッドの UsersController が_default_wrap_model
Profile モデル (名前空間なし) にアクセスしようとすると、エラーが発生します。Profile モデルの名前を変更すると (例: Info)、エラーは発生せず、すべて問題ありません。
私の質問は次のとおりです。このエラーを回避するにはどうすればよいですか?