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

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

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

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

Q&A

解決済

1回答

2588閲覧

Railsのルーティングエラー【uninitialized constant ApplicationRecord】

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby on Rails

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

0グッド

0クリップ

投稿2020/04/09 08:44

質問させていただきます。どうぞよろしくお願い申し上げます。

前提・実現したいこと

Rails5でルーティングエラーを修正したい

発生している問題・エラーメッセージ

ルーティングエラー

uninitialized constant ApplicationRecord

該当のソースコード

エラーメッセージ

Routing Error uninitialized constant ApplicationRecord Rails.root: C:/Users/R/Mysite Application Trace | Framework Trace | Full Trace app/controllers/application_controller.rb:1:in `<top (required)>' app/controllers/home_controller.rb:1:in `<top (required)>' Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url Path Match POST /home/index:id(.:format) home#show index_path GET /index(.:format) home#index users_sign_in_path GET /users/sign_in(.:format) home#sign_in users_sign_up_path GET /users/sign_up(.:format) home#sign_up post_path POST /post(.:format) home#post GET / home#top rails_service_blob_path GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation_path GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service_path GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service_path PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads_path POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create Request Parameters: None Toggle session dump _csrf_token: "rF0H5ZhGpMjby34Lzc0PMxcQLBdPFeT1kjYO91hDRHM=" session_id: "e641c9508e8db64002ae2f6ab3b072af" Toggle env dump GATEWAY_INTERFACE: "CGI/1.2" HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" HTTP_ACCEPT_ENCODING: "gzip, deflate, br" HTTP_ACCEPT_LANGUAGE: "ja,en-US;q=0.9,en;q=0.8" HTTP_CACHE_CONTROL: "max-age=0" HTTP_VERSION: "HTTP/1.1" ORIGINAL_SCRIPT_NAME: "" REMOTE_ADDR: "::1" SERVER_NAME: "localhost" SERVER_PROTOCOL: "HTTP/1.1" Response Headers: None
routes.rb Rails.application.routes.draw do post "home/index:id" => "home#show" get "/index" => "home#index" get "users/sign_in" => "home#sign_in" get "users/sign_up" => "home#sign_up" post "/post" => "home#post" get "/" => "home#top" // For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end
application.contoroller.rb class ApplicationController < ApplicationRecord # ActionController::Base # before_action :authenticate_user!, only: [:post] def redirect redirect_to("/index") end def index @videos = Video.all end def sign_in end def sign_up end def require_login end def top end def post end def show end end

index.html.erb

1<h1>投稿の一覧ページ</h1> 2<p>一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)一覧ページです(´・ω・`)</p> 3<% @videos = Video.all %> 4<% @videos.each do |video| %> 5<%= link_to("#{video.id}ページ","/index/#{video.id}")%> 6<% end %> 7

試したこと

一通り調べましたがわかりません

補足情報(FW/ツールのバージョンなど)

Windows 10 home

おねがいします(´・ω・`)

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

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

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

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

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

guest

回答1

0

ベストアンサー

class ApplicationController < ApplicationRecordですが、基底クラスがおかしいです。おそらく、class ApplicationController < ActionController::Baseとすべきところです。

投稿2020/04/09 09:01

maisumakun

総合スコア145183

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

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

退会済みユーザー

退会済みユーザー

2020/04/09 23:49

治りましたあああああああ! ありがとうございます!本当に大好きです! 一行買えただけで治るんですね!嬉しかったです!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問