前提・実現したいこと
ActiveAdminにページを追加しようとした所、500エラーになり正常に動きません。
6時間ほど格闘していましたが、他のページは正常に動いているので何故だか分かりません。
なので知恵をお借りしたいです。
宜しくお願いいたします。
発生している問題・エラーメッセージ
Processing by Admin::ItemsController#index as HTML [1m[36mUser Load (0.4ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 45 ORDER BY `users`.`id` ASC LIMIT 1[0m 竊ウ app/controllers/application_controller.rb:21 [1m[36mAdminUser Load (0.2ms)[0m [1m[34mSELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 1 ORDER BY `admin_users`.`id` ASC LIMIT 1[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 Rendering vendor/bundle/ruby/2.5.0/gems/activeadmin-2.7.0/app/views/active_admin/resource/index.html.arb [1m[35m (0.6ms)[0m [1m[34mSELECT COUNT(*) FROM (SELECT 1 AS one FROM `items` LIMIT 30 OFFSET 0) subquery_for_count[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[35mCACHE (0.0ms)[0m [1m[34mSELECT COUNT(*) FROM (SELECT 1 AS one FROM `items` LIMIT 30 OFFSET 0) subquery_for_count[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[35m (0.3ms)[0m [1m[34mSELECT COUNT(*) FROM `items`[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[35mCACHE (0.0ms)[0m [1m[34mSELECT COUNT(*) FROM (SELECT 1 AS one FROM `items` LIMIT 30 OFFSET 0) subquery_for_count[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mItem Load (0.5ms)[0m [1m[34mSELECT `items`.* FROM `items` ORDER BY `items`.`id` desc LIMIT 30 OFFSET 0[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mUser Load (0.8ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mUser Load (0.4ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m [["id", 1], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m [["id", 1], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m [["id", 1], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m [["id", 1], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mCACHE User Load (0.0ms)[0m [1m[34mSELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1[0m [["id", 3], ["LIMIT", 1]] 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 [1m[36mUser Load (0.7ms)[0m [1m[34mSELECT `users`.* FROM `users`[0m 竊ウ vendor/bundle/ruby/2.5.0/bin/unicorn_rails:23 Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.7.0/app/views/active_admin/resource/index.html.arb (228.4ms) Rendering errors/error_500.html within layouts/application Rendered errors/error_500.html within layouts/application (2.8ms) Rendered layouts/_header.html.slim (63.2ms) Rendered layouts/_footer.html.slim (11.0ms) Completed 500 Internal Server Error in 354ms (Views: 94.4ms | ActiveRecord: 5.3ms)
該当のソースコードとコマンド
itemsモデルを作って以下のコマンドを実行。
ruby
1rails generate active_admin:resource book
出来たソースコードと関係ありそうなソースコードは以下の通りです。
admin/items
Ruby
1ActiveAdmin.register Item do 2 3 # See permitted parameters documentation: 4 # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters 5 # 6 # Uncomment all parameters which should be permitted for assignment 7 # 8 # permit_params :user_id, :name, :description, :price 9 # 10 # or 11 # 12 # permit_params do 13 # permitted = [:user_id, :name, :description, :price] 14 # permitted << :other if params[:action] == 'create' && current_user.admin? 15 # permitted 16 # end 17 18end 19
db/scheme.rb
Ruby
1create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 2 t.bigint "user_id", null: false 3 t.string "name" 4 t.string "description" 5 t.integer "price" 6 t.datetime "created_at", null: false 7 t.datetime "updated_at", null: false 8 t.index ["user_id"], name: "index_items_on_user_id" 9 end 10.... 11add_foreign_key "items", "users"
itemテーブルは以下のようになっています。
|id|user_id|name|description|price|created_at|updated
|:--|:--:|--:|
|データ|データ|データ|データ|データ|データ|データ|
試したこと
1.ログをみると**SELECT users
.* FROM users
**が最後に発行されたSQLになっているのでターミナルで直接実行。
=>エラーは発生することなく正常にデータを取ることが出来ました。
2.rakeコマンドを通さずitemテーブルを少し弄ったのでscheme.rbと実際のテーブルを確認。
=>違ってるところは何も無し。
3.rake tmp:clear => 変わり無し。
4.ActiveRecord::Base.connection.query_cache.clearでアクティブレコードのキャッシュをクリア
=>変わり無し。
5.admin/items.rbでindexとcontrollerのオーバーライドをしてみるも、そもそもそこまで実行されない。
6.ルーティングが通ってないのかと思い bundle exec rails routes | grep product
=>/admin/items以下が全てある事を確認。
7.サーバごと再起動 => 変わり無し。
どなたか問題に心当たりある方いませんでしょうが。
宜しくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。