###前提・実現したいこと
教本(RubyOnRails5超入門)に従いながら、RubyOnRailsで読書カードを作っています。「localhost:3000/cards/1」とURLを叩くと、読書カードが表示されるはずなのですが、エラーになってしまいます。
showアクションを実装中に以下のエラーメッセージが発生しました。
分かる方、アドバイス願います。下記、エラー文と追加したコードになります。
###発生している問題・エラーメッセージ
Routing Error No route matches [GET] "/cards" Rails.root: C:/Users/daino/Desktop/RailsApp Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url Path Match cards_index_path GET /cards/index(.:format) cards#index cards_show_path GET /cards/show(.:format) cards#show cards_add_path GET /cards/add(.:format) cards#add cards_edit_path GET /cards/edit(.:format) cards#edit GET /people/delete/:id(.:format) people#delete GET /people/edit/:id(.:format) people#edit POST /people/edit/:id(.:format) people#update people_index_path GET /people/index(.:format) people#index people_path GET /people(.:format) people#index people_add_path GET /people/add(.:format) people#add POST /people/add(.:format) people#create GET /people/:id(.:format) people#show helo_path POST /helo(.:format) helo#index helo_index_path POST /helo/index(.:format) helo#index helo_other_path GET /helo/other(.:format) helo#other GET /helo/index(.:format) helo#index GET /helo(.:format) helo#index Request Parameters: None Toggle session dump Toggle env dump Response Headers: None
###該当のソースコード
20170403090910_create_cards.rb
class CreateCards < ActiveRecord::Migration[5.0] def change create_table :cards do |t| t.text :title t.text :author t.integer :price t.text :publisher t.text :memo t.timestamps end end end
cards_controller.rb
class CardsController < ApplicationController layout 'cards' def index @cards = Card.all end def show @card = Card.find(params[:id]) end def add if request.post? then Card.create(card_params) goback else @card = Card.new end end def edit @card = Card.find(params[:id]) if request.patch? then @card.update(card_params) goback end end def delete Card.find(params[:id]).destroy goback end private def card_params params.require(:card).permit(:title, :author, :price, :publisher, :memo) end private def goback redirect_to '/cards' end end
index.html.erb
<h1>Cards#index</h1> <p>※現在、登録されているデータの一覧です。</p> <table width="100%"> <tr> <th>ID</th><th>題名</th> <th>著者</th><th colspan="2"></th> </tr> <%= @cards.each do |obj| %> <tr> <td width="35px"><%= obj.id %></td> <td width="50px"><a href="/cards/<% = obj.id %>"><%= obj.title %></a></td> <td><%= obj.author %></td> <td width="40px"><a href="/cards/edit/<%= obj.id %>">編集</a></td> <td width="40px"><a href ="javascript:window.delData(<%= (obj.id.to_s + ",'".to_s + obj.title.to_s).html_safe %>');">削除</a></td> </tr> <% end %> </table> <p class ="link"><a href="/cards/add">※新しいデータを入力 >></a></p>
###試したこと
・Routingの確認
・書き写しの抜け漏れチェック
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/04 03:20
2017/04/05 00:55
2017/04/05 01:54
2017/04/05 01:59
2017/04/05 02:03
2017/04/05 02:19
2017/04/05 02:24
2017/04/05 02:32
2017/04/05 05:42
2017/04/05 05:49
2017/04/05 05:51
2017/04/05 06:01
2017/04/05 06:14
2017/04/05 06:30
2017/04/05 06:39 編集
2017/04/05 06:42
2017/04/05 06:51 編集
2017/04/05 06:58
2017/04/05 07:21
2017/04/05 07:47
2017/04/05 08:09