我有一個針對房地產經紀人的評級系統。我有一個代理模型和一個agent_review模型。評分存儲在agent_review表中,但我需要在代理模型下的視圖中顯示平均評分,並且遇到了一些問題。所有代碼都張貼在下面,請提前謝謝。NoMethodError與Rails 4中的兩個模型一起工作4
代理模型:
has_many :agent_reviews
agent_review模型:
belongs_to :agent
代理視圖:
<h3>Agent Rating: <%= @agent.agent_reviews.rating %> (<%= @agent.agent_reviews.count %>)</h3>
代理控制器顯示方法:
def show
@agent_reviews = AgentReview.all
@agent = Agent.find_by_slug(params[:id]) || Agent.find(params[:id])
if @agent.private_profile? && !current_agent&.super_admin?
redirect_to root_path, notice: "That user has a private profile"
else
@favorite_listings = @agent.liked_listings.available.includes(:neighborhood)
@agent_listings = @agent.sales_agent_listings.available.visible
@mate_posts = @agent.liked_mates.order(:when)
respond_to do |format|
format.html
format.json { render json: @agent }
end
end
end
錯誤:
顯示從您的終端完整的錯誤日誌 – luissimo