在ROR中活动管理员“awesome nested set”gem中显示不必要的文本

时间:2015-10-08 05:45:33

标签: ruby-on-rails

我在ROR中使用了很棒的嵌套set gem,它运行正常但是在添加形式时,显示了不必要的文本。

#<#<Class:0x00000006fa4c30>:0x00000006f7fe30>

这是我的代码

控制器

ActiveAdmin.register Category do
  permit_params :name, :lft, :rgt, :parent_id, :depth
  # Set the default sort order.
  config.sort_order = 'lft_asc'
  # Add member actions for positioning.

  sortable_tree_member_actions
  form do |f|
    f.inputs do
      f.input :parent, :as => :select, :collection => f.template.nested_set_options(Category, @category) {|i| "#{'--' * i.level} #{i.name}" }
      #f.input :parent, :as => :select, :collection => Category.where("parent_id IS NULL")
      f.input :name
    end # f.inputs
    f.actions
  end # form

  index do
    # This adds columns for moving up, down, top and bottom.
    sortable_tree_columns
    sortable_tree_indented_column :name
    actions
  end
end

模型

class Category < ActiveRecord::Base
  # awesome nested set
  acts_as_nested_set
  validates :name, :presence => true
  #default_scope :order => 'lft ASC'

  #...
end

Please look into this

1 个答案:

答案 0 :(得分:0)

f.input :parent, :as => :select, :collection => nested_set_options(Category, @category) {|i| "#{'--' * i.level} #{i.name}" }

删除f.template,它将不会打印出来