質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

2307閲覧

500 Internal Server Error

Masashige1005

総合スコア14

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/04/28 08:48

編集2020/04/28 08:59

500 Internal Server Error 

上記のエラーで困っております。
開発環境
docker
ruby on rails6

gem
devise

現在はログインページを少しいじったぐらいなのですがこのエラーの理由が全くわかりません。

Started GET "/admin_users" for 172.18.0.1 at 2020-04-28 08:39:32 +0000
Processing by AdminUsersController#index as HTML
Rendering admin_users/index.html.erb within layouts/application
AdminUser Load (2.7ms) SELECT admin_users.* FROM admin_users
↳ app/views/admin_users/index.html.erb:15
Rendered admin_users/index.html.erb within layouts/application (Duration: 12.3ms | Allocations: 1014)
Completed 500 Internal Server Error in 138ms (ActiveRecord: 2.7ms | Allocations: 4076)

admin_users/indexページに飛ぶところで毎回以下のページに行ってしまいます。

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

index

1 2<p id="notice"><%= notice %></p> 3 4<h1>Admin Users</h1> 5 6<table> 7 <thead> 8 <tr> 9 <th>Index</th> 10 <th>Show</th> 11 <th colspan="3"></th> 12 </tr> 13 </thead> 14 15 <tbody> 16 <% @admin_users.each do |admin_user| %> 17 <tr> 18 <td><%= admin_user.id %></td> 19 <td><%= admin_user.membername %></td> 20 <td><%= link_to 'Show', admin_user_path(admin_user.id) %></td> 21 <td><%= link_to 'Edit', edit_admin_user_path(admin_user) %></td> 22 <td><%= link_to 'Destroy', admin_user_path(admin_user.id), method: :delete, data: { confirm: 'Are you sure?' } %></td> 23 </tr> 24 <% end %> 25 </tbody> 26</table> 27 28<br> 29 30<%= link_to 'New Admin User', new_admin_user_path %> 31

model

1class AdminUser < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6end

controller

1class AdminUsersController < ApplicationController 2 before_action :set_admin_user, only: [:show, :edit, :update, :destroy] 3 4 # GET /admin_users 5 # GET /admin_users.json 6 def index 7 @admin_users = AdminUser.all 8 end 9 10 # GET /admin_users/1 11 # GET /admin_users/1.json 12 def show 13 end 14 15 # GET /admin_users/new 16 def new 17 @admin_user = AdminUser.new 18 end 19 20 # GET /admin_users/1/edit 21 def edit 22 end 23 24 # POST /admin_users 25 # POST /admin_users.json 26 def create 27 @admin_user = AdminUser.new(admin_user_params) 28 29 respond_to do |format| 30 if @admin_user.save 31 format.html { redirect_to @admin_user, notice: 'Admin user was successfully created.' } 32 format.json { render :show, status: :created, location: @admin_user } 33 else 34 format.html { render :new } 35 format.json { render json: @admin_user.errors, status: :unprocessable_entity } 36 end 37 end 38 end 39 40 # PATCH/PUT /admin_users/1 41 # PATCH/PUT /admin_users/1.json 42 def update 43 respond_to do |format| 44 if @admin_user.update(admin_user_params) 45 format.html { redirect_to @admin_user, notice: 'Admin user was successfully updated.' } 46 format.json { render :show, status: :ok, location: @admin_user } 47 else 48 format.html { render :edit } 49 format.json { render json: @admin_user.errors, status: :unprocessable_entity } 50 end 51 end 52 end 53 54 # DELETE /admin_users/1 55 # DELETE /admin_users/1.json 56 def destroy 57 @admin_user.destroy 58 respond_to do |format| 59 format.html { redirect_to admin_users_url, notice: 'Admin user was successfully destroyed.' } 60 format.json { head :no_content } 61 end 62 end 63 64 private 65 # Use callbacks to share common setup or constraints between actions. 66 def set_admin_user 67 @admin_user = AdminUser.find(params[:id]) 68 end 69 70 # Only allow a list of trusted parameters through. 71 def admin_user_params 72 params.require(:admin_user).permit(:index, :show) 73 end 74end 75

routes

1Rails.application.routes.draw do 2 3 resources :admin_users 4 devise_for :admin_users 5 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 6end

解決方法知っている方いたらよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2020/04/28 09:50

Completed 500 Internal Server Error in 138ms (ActiveRecord: 2.7ms | Allocations: 4076) この先にもう少しエラーっメッセージ続いてませんか?
Masashige1005

2020/04/28 10:04

この先にエラー文はありませんでしたね。 development.logにも何もなかったです・・・
winterboum

2020/04/28 10:07

どのfileのどの行でどういうエラー というのがなかった? 例えば Completed 500 Internal Server Error in 11567ms (ActiveRecord: 173.8ms) NoMethodError - undefined method `estate' for nil:NilClass: app/controllers/admin/hosts_controller.rb:173:in `update_real' こんなように
asm

2020/04/29 03:12 編集

development環境だともう少し詳しいエラーでるし production環境なんじゃないかな? もしそうなら見るべきはlog/production.logです。
winterboum

2020/04/29 02:25

We're sorry, but something went wrong. ってことは productin ですね
guest

回答1

0

ベストアンサー

arrayが空だとエラー起こってる的な感じですかね?

def index @admin_users = AdminUser.all # -> [] 、つまり空? end

あと、以下のメッセージが出るってことは開発環境のエラーではないので、
まずはこちらの記事を参考にエラーを出してみてください
【rails】本番環境でもエラー文を表示させる

We're sorry, but something went wrong. If you are the application owner check the logs for more information.

上記を試してエラーを確認して、それでも解決できなければまた追記お願いします。

※コードやエラー情報は見やすいように"コード"として扱った方が質問者もより早く集まるかと

投稿2020/04/29 03:04

hiyashikyuri

総合スコア388

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問