Class: EasyAdmin::Types::JsonType

Inherits:
ActiveRecord::Type::Json
  • Object
show all
Defined in:
lib/easy_admin/types/json_type.rb

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/easy_admin/types/json_type.rb', line 9

def cast(value)
  case value
  when String
    # Handle JSON strings from form inputs
    begin
      JSON.parse(value)
    rescue JSON::ParserError
      value # Return original string if not valid JSON
    end
  else
    # Let Rails handle other types
    super
  end
end

#typeObject

Inherit from Rails’ native JSON type for better compatibility



5
6
7
# File 'lib/easy_admin/types/json_type.rb', line 5

def type
  :json
end