Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem, when object is subclass. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions lib/activeadmin/resource_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ module ActiveAdmin
class ResourceDSL
def json_editor
before_save do |object, _args|
request_namespace = object.class.name.underscore.tr('/', '_')
if params.key? request_namespace
object.class.columns_hash.select { |_key, attr| attr.type.in? [:json, :jsonb] }.keys.each do |key|
next unless params[request_namespace].key? key
json_data = params[request_namespace][key]
data = if json_data == 'null' || json_data.blank?
{}
else
JSON.parse(json_data)
end
object.attributes = { key => data }
object.class.columns_hash.select { |_key, attr| attr.type.in? [:json, :jsonb] }.keys.each do |key|
next unless params[resource_request_name].key? key
json_data = params[resource_request_name][key]
data = if json_data == 'null' || json_data.blank?
{}
else
JSON.parse(json_data)
end
else
raise ActionController::ParameterMissing, request_namespace
object.attributes = { key => data }
end
end
end
Expand Down