Sha256: dc47ce533ea026def3a7c80ee7c32e865d2c440849c88d467de35d3a16e01485

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'active_admin'

module ActiveAdmin
  module DynamicFields
    class Engine < ::Rails::Engine
      engine_name 'activeadmin_dynamic_fields'
    end

    def self.edit_boolean( field, url, value )
      { 'data-field': field, 'data-field-type': 'boolean', 'data-field-value': value, 'data-content': "<span class=\"status_tag changed\">#{value ? 'no' : 'yes'}</span>", 'data-save-url': url, 'data-show-errors': '1' }
    end

    def self.edit_select( field, url )
      { 'data-field': field, 'data-field-type': 'select', 'data-save-url': url, 'data-show-errors': '1' }
    end

    def self.edit_string( field, url )
      { contenteditable: true, 'data-field': field, 'data-field-type': 'string', 'data-save-url': url, 'data-show-errors': '1' }
    end

    def self.update( resource, params, permit_params = nil )
      if params[:data]
        if resource.update( permit_params ? params[:data].permit( permit_params ) : params[:data].permit! )
          { json: { status: 'ok' } }
        else
          { json: { status: 'error', message: resource.errors } }
        end
      else
        { json: { status: 'error', message: 'No data' }, status: 400 }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin_dynamic_fields-0.2.2 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.2.1 lib/activeadmin/dynamic_fields/engine.rb