Unsupported field datatype: metadata

463 views Asked by At

I have this error message:

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

I'm doing this presentation about the gem rails_admin. And in the slide 29 I put that in the Post and than has this error. My files:

/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
1

There are 1 answers

1
dalpo On

You have to require "#{Rails.root}/lib/rails_admin/metadata" in the head of rails_admin initializer.

Or add the lib folder in the rails autoload paths.

In your config/application.rb add: config.autoload_paths = %W(#{config.root}/lib)

Btw the serialized datatype in rails_admin is already implemented: https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/fields/types/serialized.rb