railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

Access bindings[:object] outside of field block #2587

Closed dmitrypol closed 5 years ago

dmitrypol commented 8 years ago

I want to enable my users to switch between bootstrap-wysihtml5-rails and wysiwyg-rails (Froala) editors depending on model setting. But I cannot access bindings[:object] outside of field block. Does anyone have suggestions?

I am using Rails 4.1.14 with RailsAdmin 0.8.1. I thank you in advance for any advice.

class MyModel
  include Mongoid::Document
  field :body, type: String
  field :body_editor
  extend Enumerize
  enumerize :body_editor, in: [:froala, :wysihtml5]

  rails_admin do
    edit do
      # this causes error   undefined method `[]' for nil:NilClass
      if bindings[:object].body_editor == :wysihtml5
        field :body, :wysihtml5 do           
          config_options toolbar: { fa: true, html: true, color: true } end
      else
        field :body, :froala do
          config_options do
            ...
          end
        end
      end
    end
  end
end
aantsyferova commented 5 years ago

@dmitrypol have you ever fixed this?

dmitrypol commented 5 years ago

no, never did.