我的模型是:
class City < ActiveRecord::Base
belongs_to :region
has_many :activities
has_many :restaurants
end
class Activity < ActiveRecord::Base
belongs_to :city
end
在城市索引页面上,我想根据每个循环中的布尔值显示所有城市的活动和餐厅。
我的城市管理员:
def index
@region = Region.find(params[:region_id])
@cities = @region.cities
@activities = @cities.activities.find_all_by_homepage_city(true)
@restaurants = @city.restaurants.find_all_by_homepage_city(true)
@activities_restaurants = @activities + @restaurants
end
查看城市索引页面
- @activities_restaurants.each do |b|
%li
=link_to b.name, polymorphic_path([@region, @city, b])
我收到错误消息“未定义的方法‘活动’”我做错了什么?