【问题标题】:Acts-As_Taggable & Administrate Gem - uninitialized constant ActsAsTaggableOn::TagDashboardActs-As_Taggable & Administrate Gem - 未初始化的常量 ActsAsTaggableOn::TagDashboard
【发布时间】:2016-09-01 15:08:47
【问题描述】:

我收到此错误:ActionView::Template::Error: uninitialized constant ActsAsTaggableOn::TagDashboard 您的意思是? PlanDashboard GoalDashboard TaskDashboard

我真的希望它是 UserDashboard,但不确定我需要在下面添加或更改什么。有任何想法吗?非常感谢。


所以我设置了我的 Adminstrate gem,我可以展示我的模型(包括用户)。 但是当我点击编辑时,我得到了上面的错误。

我正在使用以下相关的 gems

ruby "2.3.1"

gem "rails", "5.0.0.1"

gem "pg", "0.18.4" # postgresql database
gem "acts-as-taggable-on", git: "https://github.com/mbleigh/acts-as-taggable-on" # tagging
gem "administrate", git: "https://github.com/heyogrady/administrate", branch: "rails5"

下面是我的代码:

enter code here`require "administrate/base_dashboard"

class UserDashboard < Administrate::BaseDashboard

  # ATTRIBUTE_TYPES
  # a hash that describes the type of each of the model's fields.
  #
  # Each different type represents an Administrate::Field object,
  # which determines how the attribute is displayed
  # on pages throughout the dashboard.
  ATTRIBUTE_TYPES = {
    owned_taggings: Field::HasMany.with_options(class_name: "::ActsAsTaggableOn::Tagging"),
    owned_tags: Field::HasMany.with_options(class_name: "::ActsAsTaggableOn::Tag"),
    team_group: Field::BelongsTo,
    lead_groups: Field::HasMany,
...
  }

  # COLLECTION_ATTRIBUTES
  # an array of attributes that will be displayed on the model's index page.
  #
  # By default, it's limited to four items to reduce clutter on index pages.
  # Feel free to add, remove, or rearrange items.
  COLLECTION_ATTRIBUTES = [
    :name,
    :email,
...
  ]

  # SHOW_PAGE_ATTRIBUTES
  # an array of attributes that will be displayed on the model's show page.
  SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys

  # FORM_ATTRIBUTES
  # an array of attributes that will be displayed
  # on the model's form (`new` and `edit`) pages.
  FORM_ATTRIBUTES = [
    :owned_taggings,
    :owned_tags,
    :team_group,
    :lead_groups,
...
  ]

  # Overwrite this method to customize how users are displayed
  # across all pages of the admin dashboard.
  #
  def display_resource(user)
    user.name
  end

end

【问题讨论】:

    标签: ruby-on-rails ruby rubygems acts-as-taggable-on


    【解决方案1】:

    只需像这样删除ATTRIBUTE_TYPES 中涉及Tags 的行:

    ATTRIBUTE_TYPES = {
    # taggings: Field::HasMany.with_options(class_name: "::ActsAsTaggableOn::Tagging"),
    # base_tags: Field::HasMany.with_options(class_name: "::ActsAsTaggableOn::Tag"),
    # tag_taggings: Field::HasMany.with_options(class_name: "ActsAsTaggableOn::Tagging"),
    # tags: Field::HasMany.with_options(class_name: "ActsAsTaggableOn::Tag"),
    # topic_taggings: Field::HasMany.with_options(class_name: "ActsAsTaggableOn::Tagging"),
    # topics: Field::HasMany.with_options(class_name: "ActsAsTaggableOn::Tag"),
    user: Field::BelongsTo,
    tag_list: Field::String,
    id: Field::Number,
    title: Field::String,
    body: Field::Text,
    

    同时删除COLLECTION_ATTRIBUTESSHOW_PAGE_ATTRIBUTESFORM_ATTRIBUTES 中涉及Tags 的行。

    如果您想在模型上显示/编辑标签,请将此行添加到ATTRIBUTE_TYPES

    tag_list: Field::String,

    现在您可以在COLLECTION_ATTRIBUTESSHOW_PAGE_ATTRIBUTESFORM_ATTRIBUTES 中使用:tag_list,

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多