简体   繁体   中英

Make jsoneditor in Active Admin read-only through Ruby?

I'm editing a form in Active Admin/Formtastic, which includes a jsoneditor input. Under some circumstances, though, the JSON should be locked and uneditable, in which case I'd want to use the view mode so it can be read but not changed. Is there a way to do this on the Ruby side? The current code looks something like this.

form do |f|
    f.inputs do
        input(:my_data, as: :jsonb)
    end
end

I've tried as: :text, input_html: { disabled: true } , but that makes the JSON pretty much unreadable.

You could wrap you JSON in a <code> block using ActiveAdmin's Arbre for cases when it should be readonly. Here's a rough example:

Arbre::Context.new do
  code JSON.pretty_generate(:my_data)
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM