我有留言揚聲器模型。 我想要顯示每個發言者在頁面索引頁上發佈的消息數量。當我插入@speaker = Speaker.find(params [:id])它顯示錯誤無法找到揚聲器'id'=。我不明白我做錯了什麼。
我的網頁控制器
class PagesController < ApplicationController
def home
@messages = Message.all.order("created_at DESC")
@speakers = Speaker.all
@speaker = Speaker.find(params[:id])
@count = @speaker.messages.count
@listeners = Listener.all
end
def about
end
def show
@speaker = Speaker.find(params[:id])
end
end
和我家的觀點
<%= @count %> Messages
嘗試在每個* find *前打印params [:id]的值,確保它是一個數字 –