【发布时间】:2015-06-24 23:13:00
【问题描述】:
我正在尝试在我的应用中创建一个菜单,为我的 Places 模型的每个类别显示一个链接。
我做到了,但仅在我第一次访问我的应用程序时有效,之后我收到此错误
应用程序中的名称错误#index
未初始化的常量 ActsAsTaggableOn::Category
Extracted source (around line #9):
7
8
9
10
11
12
@places = Place.all
@states = State.all
@categories = ActsAsTaggableOn::Category.all
end
如果我重新启动我的 Rails 服务器,我的菜单会在第一次运行时再次出现错误。
我的应用程序控制器
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def index
@places = Place.all
@states = State.all
@categories = ActsAsTaggableOn::Category.all
end
end
我的地点
class Place < ActiveRecord::Base
validates_presence_of :name , :state, :city, :neighborhood, :adress,:latitude, :longitude
belongs_to :user
acts_as_ordered_taggable_on :categories, :obstacles
end
Index.erb 菜单代码
<% categories.each do |category| %>
<li><a href="#"><i class="fa fa-cutlery"></i><%= category.name%> <span>32</span></a></li>
<%end %>
【问题讨论】:
-
请不要编辑您问题的基本前提。另外,不要编辑问题的标题,请accept an answer 这对您有帮助。
标签: ruby-on-rails acts-as-taggable-on