###前提・実現したいこと
index.htmlから詳細画面のshowに飛び、habits/1のような個別のidがついたurlで呼び出したいのですが、habits/id(id=id)のようになります。
ルーティングは、resources :habitsです。
どこが問題なのかわからず、苦戦しています。初歩的な質問で申し訳ございませんが、教えていただけると幸甚です!
ActiveRecord::RecordNotFound in HabitsController#show Couldn't find Habit with 'id'=id
###controller and index.html
class HabitsController < ApplicationController before_action :find_by_id, only:[:show, :edit, :update, :destroy] def index @habits = Habit.all end def show end private def find_by_id @habit = Habit.find(params[:id]) end //index.html.erb <% @habits.each do |hb| %> <table class="habit_table"> <tr> <td><%= link_to hb.routine, habit_path(:id) %></td> <td>継続記録<%= hb.days %>日</td> <td><%= link_to "Edit", edit_habit_path(:id) %></td> <td><%= link_to "Delete", habit_path(:id), method: :delete, data: { confirm: "Are You Sure to Delete ?"} %></td> </tr> </table>

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。