0

这是我的控制器的样子

class RestaurantsController < ApplicationController

    def index
        @restaurant = Restaurant.find(1)
    end 

    def new 
    end 
end

这是我的看法

Friendliness: <%= rating_for @restaurant, "friendliness" %>
Taste : <%= rating_for @restaurant, "taste" %>
Price : <%= rating_for @restaurant, "price" %>

我已经去 Rails 控制台制作了多家餐厅。

问题是当我将控制器中的索引方法更改为此

def index
  @restaurants = Restaurant.all
end 

并更改@restaurant to @restaurants了视图。

<%= rating_for %>是 gem 中的一个辅助方法,它允许我创建一个星级评分系统,就像 yelp 一样

问题是这行不通?我不断得到

 (undefined method `average' for nil:NilClass):

这意味着“@restaurants”没有被初始化,但它应该被初始化。letrate gem 允许您向模型添加评级功能。

4

0 回答 0