我在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
答案 0 :(得分:0)
f.input :parent, :as => :select, :collection => nested_set_options(Category, @category) {|i| "#{'--' * i.level} #{i.name}" }
删除f.template,它将不会打印出来