我有以下错误消息:
Unsupported field datatype: metadata.
Extracted source (around line #23):
21 end
22
23 configure :block, :metadata
24
25 configure :sticky, :metadata do
26 view_helper :check_box
关于gem rails_admin我正在做presentation。在幻灯片29中我把它放在邮政中,而不是有这个错误。 我的档案:
/lib/rails_admin/metadata.rb
require 'rails_admin/config/fields/base'
module RailsAdmin
class Metadata < RailsAdmin::Config::Fields::base
RailsAdmin::Config::Fields::Types::register(self)
def value
raise 'No metadata!' unless bindings[:object].respond_to?(:metadata)
bindings[:object].metadata[method_name]
end
def allowed_methods
'metadata'
end
def parse_input(params)
params['metadata'] ||= bindings[:object].metadata
params['metadata'] [method_name] = params.delete(method_name)
end
end
end
/models/blog/post.rb
class Blog::Post < ActiveRecord::Base
has_many :comments
belongs_to :user
accepts_nested_attributes_for :comments
serialize :metadata, Hash
rails_admin do
configure :user do
visible do
bindings[:controller].current_ability.can? :edit, User
end
end
configure :comments do
visible do
bindings[:controller].current_ability.can? :edit, Blog::comment
end
end
configure :block, :metadata
configure :sticky, :metadata do
view_helper :check_box
end
configure :published, :metadata do
view_helper :check_box
end
configure :priority, :metadata do
view_helper :number_field
defaul_value 0
end
end
end
答案 0 :(得分:1)
你必须在rails_admin初始化程序的头部random.choice()
。
或者在rails自动加载路径中添加require "#{Rails.root}/lib/rails_admin/metadata"
文件夹。
在lib
添加:
config/application.rb
btw已经实现了rails_admin中的序列化数据类型:https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/fields/types/serialized.rb