3

Are there another ways of representing a array type field in rails_admin?

Now it looks: - alsace - france - french - pinot blanc - dry
where array items are separated by - symbol.

1 Answer 1

4

I introduced transient fields for this:

class KnowHow
  include Mongoid::Document

  SPLITTER = ','

  field :category, type: String
  field :content_array, type: Array

  def content
    (content_array || []).join(SPLITTER)
  end

  def content=(items)
    if items.present?
      self.content_array = items.split(SPLITTER).map(&:strip).reject(&:blank?)
    else
      self.content_array = []
    end
  end

  rails_admin do
    field :category
    field :content
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.