前提
controllerで取得したデータをif文の条件で使いたいのですがエラーが発生しました。
メソッドが見つからないのはなぜでしょうか?
発生している問題・エラーメッセージ
!更新10/07 21:55
NoMethodError at /plans/18 undefined method `plan_id' for #<ActiveRecord::Relation [#<Room id: 1, room_name: "aaaaaaaaaaaaaa", created_at: "2022-10-07 13:07:47.438365000 +0900", updated_at: "2022-10-07 13:07:47.438365000 +0900", plan_id: 18>]>
該当のソースコード
!更新10/08 0:30
plans_controller.rb
1@room = Room.all.find_by(plan_id: @plan.id)
!更新10/07 21:55
views/plans/show.html.erb
1<% if @plan.id == @room %> 2 <p class="user-show-room"><a href="/rooms/<%= @roomId %>"class="btn btn-primary btn-lg">メッセージ</a> 3<% end %>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。