rails勉強中です。rails チュートリアルにあるトイMVCを少し発展させたいなと思いチャレンジしています。
model内容をちょこっと変更しただけなのですが、show アクションがうまく動きません。
URL上に直接idを打ち込むと正常にブラウザーで確認できるのですが、indexページのshowをクリックするとidが見つからないとエラーが出てしまいます。
このようなケースの場合はどうすればよいのでしょうか。
どうぞよろしくお願いいたします
<routes> Rails.application.routes.draw do root 'topic_table#index' get 'topic_table/index' get 'topic_table/show' get 'topic_table/new' get 'topic_table/edit' get '/topic_table' , to:'topic_table#index' get '/topic_table/:id' ,to:'topic_table#show' get '/topic_table/new', to: 'topic_table#new' post '/topic_table' , to:'topic_table#create' <show.html.erb> <h1>Staff details</h1> <p> <strong>Name:</strong> <%= @user.name %> </p> <p> <strong>Email:</strong> <%= @user.email %> </p> <p> <strong>Birthday:</strong> <%= @user.birthday %> </p> <p> <strong>Memo:</strong> <%= @user.memo %> </p> <%=link_to"view all staff","/"%> <index.html.erb> <body> <% @users.each do |user|%> <tr> <td><%= user.id %></td> <td><%= user.name %></td> <td><%= user.email %></td> <td><%= user.birthday %></td> <td><%= user.memo %></td> <td><%=link_to"show","/topic_table/:id"%></td> <td><%=link_to"Edit","#"%></td> <td><%=link_to"Destroy","#"%></td> <% end %> </tr> </body> class TopicTableController < ApplicationController def index @users = User.all end def new @user = User.new end def show @user = User.find(params[:id]) end def edit end def update @user = User.find(params[:id]) if @use.update(user_params) redirect_to ("/topic_table/:id") else render 'edit' end end def create @user = User.new(user_params) @user.save redirect_to ("/topic_table/:id") end private def user_params params.require(:user).permit(:name, :email,:birthday,:memo) end end <model> class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.string :email t.date :birthday t.text :memo t.timestamps null: false end end end コード ```引用テキスト![イメージ説明](fdbca9f053dc8d2d807d4ed40550680c.png)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。