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

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

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

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

解決済

1回答

406閲覧

rails show アクションについて エラーが出てしまう

Marge0101

総合スコア15

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

0クリップ

投稿2017/11/16 15:52

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)

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

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

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

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

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

guest

回答1

0

ベストアンサー

特に理由がないのであれば、レールに乗る(Rails標準のやり方で進める)ことをおすすめします。

resources :topic_tablesと書くだけで、TopicTablesControllerに対するindexshowneweditcreateupdatedestroyの7つのアクションが揃います。

特殊な操作が必要でもないのに、わざわざ自分で書いて間違えるのは(練習でやっているなら別ですが)時間の無駄です。

投稿2017/11/17 00:20

maisumakun

総合スコア145184

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問