ルビー: 2.5.1、レール: 5.1.6
場合によっては、このエラーが開発環境でのみ表示されることがあります。そして、複数のプラットフォームで。ruby が「rbenv」または「rvm」のどちらにインストールされているか。
Started GET "/notifications" for 127.0.0.1 at 2018-08-27 14:51:47 +0200
Processing by NotificationsController#index as */*
Started GET "/dashboard_widgets/my_courses/1" for 127.0.0.1 at 2018-08-27 14:51:47 +0200
Started GET "/dashboard_widgets/appointments/2" for 127.0.0.1 at 2018-08-27 14:51:47 +0200
Started GET "/dashboard_widgets/calendars/4" for 127.0.0.1 at 2018-08-27 14:51:47 +0200
Started GET "/dashboard_widgets/tasks/3" for 127.0.0.1 at 2018-08-27 14:51:47 +0200
Account Load (1.0ms) SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = '' LIMIT 1
User Load (61.4ms) SELECT `users`.* FROM `users` WHERE `users`.`account_id` = 1 AND `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
AccountSetting Load (1.3ms) SELECT `settings`.* FROM `settings` WHERE `settings`.`target_id` = 1 AND `settings`.`target_type` = 'Account'
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: already initialized constant DashboardWidgets
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: previous definition of DashboardWidgets was here
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: already initialized constant DashboardWidgets
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: previous definition of DashboardWidgets was here
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: already initialized constant DashboardWidgets
/Users/alexander/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:457: warning: previous definition of DashboardWidgets was here
LoadError (Unable to autoload constant DashboardWidgets::MyCoursesController, expected /Users/alexander/rails_projects/tutorize-business-solutions/app/controllers/dashboard_widgets/my_courses_controller.rb to define it):
Processing by DashboardWidgets::TasksController#show as HTML
Parameters: {"id"=>"3"}
LoadError (Unable to autoload constant DashboardWidgets::AppointmentsController, expected /Users/alexander/rails_projects/tutorize-business-solutions/app/controllers/dashboard_widgets/appointments_controller.rb to define it):
LoadError (Unable to autoload constant DashboardWidgets::CalendarsController, expected /Users/alexander/rails_projects/tutorize-business-solutions/app/controllers/dashboard_widgets/calendars_controller.rb to define it):
appsignal (2.3.7) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
appsignal (2.3.7) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
(7.9ms) SET NAMES utf8mb4, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
appsignal (2.3.7) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
Account Load (21.9ms) SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = '' LIMIT 1
User Load (2.4ms) SELECT `users`.* FROM `users` WHERE `users`.`account_id` = 1 AND `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
AccountSetting Load (1.3ms) SELECT `settings`.* FROM `settings` WHERE `settings`.`target_id` = 1 AND `settings`.`target_type` = 'Account'
DashboardWidget Load (4.5ms) SELECT `dashboard_widgets`.* FROM `dashboard_widgets` WHERE `dashboard_widgets`.`account_id` = 1 AND `dashboard_widgets`.`id` = 3 ORDER BY `dashboard_widgets`.`position` ASC LIMIT 1
Rendering dashboard_widgets/tasks/show.html.erb
DashboardWidgetShare Load (3.5ms) SELECT `dashboard_widget_shares`.* FROM `dashboard_widget_shares` WHERE `dashboard_widget_shares`.`account_id` = 1 AND `dashboard_widget_shares`.`dashboard_widget_id` = 3 LIMIT 1
Task Load (1.1ms) SELECT `tasks`.* FROM `tasks` WHERE `tasks`.`account_id` = 1 AND `tasks`.`deleted_at` IS NULL AND `tasks`.`user_id` = 1 AND `tasks`.`status` = 'opened' ORDER BY `tasks`.`due_date` DESC LIMIT 10
Rendered dashboard_widgets/tasks/layouts/_widget.html.erb (39.1ms)
Rendered dashboard_widgets/tasks/show.html.erb (82.7ms)
Completed 200 OK in 959ms (Views: 116.0ms | ActiveRecord: 51.2ms)
my_courses_controller.rb
および他のすべてのコントローラのパスは正しく、再確認されています。奇妙なことに、2 番目の要求が来るとすぐに、すべてが機能します。本番環境は今のところ問題ないようです。レールautoload_path
は延長されていません。
構造のコード例:
module DashboardWidgets
class WidgetsController < ::ApplicationController
private
def set_user
# sets user and stuff...
end
end
end
module DashboardWidgets
class MyCoursesController < WidgetsController
include CustomView
layout false
def show
authorize [:dashboard_widgets, :my_course]
set_dashboard_widget
set_user
search = Searches::LmsSearch.new current_user.learning_course_ids_by_type.merge(search_params)
@courses = search.search
render_custom_view
end
...
end
一般的な「既に初期化された定数 X」エラーと「X の以前の定義」警告を何週間も検索しましたが、まだ何が問題なのかまったくわかりません。