Sha256: 224eedaf132c8f9755eb206951fdf4d0d82428a908dda7bebd0efab53a8d6775
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 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' } # 'data-field': 'author_id', 'data-field-type': 'select', 'data-save-url': save_admin_article_path( row.id ), 'data-show-errors': '1' do # ( [''] + Author.pluck( :name, :id ) ).map{ |opt| option opt[0], value: opt[1], selected: row.author_id == opt[1] }.join # end 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activeadmin_dynamic_fields-0.2.0 | lib/activeadmin/dynamic_fields/engine.rb |