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

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

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

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

Ruby on Rails

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

Q&A

解決済

1回答

1083閲覧

Routing Errorが出てしまいます。。。

ebi---kani

総合スコア3

Ruby

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

Ruby on Rails

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

0グッド

0クリップ

投稿2021/03/22 09:24

#Routing Error
Routing Error
uninitialized constant EntryController Did you mean? EntrysController

#内容
show.html.erbのlink_toから"大会に参加する"をクリックするとentryのindexのビューファイルに遷移させたいのですが、ルーティングエラーがでます。
pathが間違っているかと思い、rails routesで確認したのですがうまく実装できません。

##controller コード

ruby:entrys.controller

1class EntrysController < ApplicationController 2 before_action :authenticate_user! 3 before_action :set_product, only: [:index,:create] 4 5 6 7 def index 8 @entry = Entry.new 9 end 10 11 def create 12 @entry = Entry.new(entry_params) 13 end 14 15 16 17 private 18 19 def entry_params 20 params.require(:entry).permit(:team_name,:team_captain,:phone).merge(user_id:current_user.id,tournament_id:@tournament.id) 21 end 22 23 def set_product 24 @product = Product.find(params[:product_id]) 25 end 26 27 28end

##routes コード

ruby:routes.rb

1Rails.application.routes.draw do 2 devise_for :operations 3 devise_for :users 4 root to: "tournaments#index" 5 resources :tournaments do 6 resources :entry, only:[:index,:create] 7 end 8end

##model コード

ruby:entry.rb

1class Entry < ApplicationRecord 2 belongs_to :tournament 3 belongs_to :user 4 5end

##show コード

ruby:show.html.erb

1 2上記省略 3 4<% if operation_signed_in? %> 5 <% if current_operation.id == @tournament.operation.id %> 6 <%= link_to "大会情報 編集", edit_tournament_path(@tournament.id),method: :get, class:"btn" %> 7 <%= link_to "大会情報 削除",tournament_path(@tournament.id),method: :delete, class:"delete_btn" %> 8 <% end %> 9 <% end %> 10 11 <% if user_signed_in? %> 12 <%= link_to "大会に参加する", tournament_entry_index_path(@tournament.id),class:"entry_btn" %> 13 <% end %> 14

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

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

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

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

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

guest

回答1

0

自己解決

routes.rbでルーティングの設定時に
resources :entryとなっていたのをresources :entrysに変更して解決しました。

投稿2021/03/22 10:02

ebi---kani

総合スコア3

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

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

maisumakun

2021/03/22 11:50

本題ではありませんが、英単語としてのentryの複数形はentriesなので、それに従って名前を設定しておいたほうが、あとあとトラブルに巻き込まれるリスクが低いと考えます。
ebi---kani

2021/03/23 03:48

ありがとうございます! 複数形の仕方も考えながら実装致します!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問