From 9f465f2df7da1c8c4ca85068ed4b8e9067d1a222 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Wed, 1 Jan 2020 10:16:04 +0000 Subject: [PATCH] Move class methods to top to avoid confusion --- lib/administrate/field/base.rb | 8 ++++---- lib/administrate/field/has_one.rb | 14 +++++++------- lib/administrate/field/polymorphic.rb | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/administrate/field/base.rb b/lib/administrate/field/base.rb index e7d017ba1d..83237f7820 100644 --- a/lib/administrate/field/base.rb +++ b/lib/administrate/field/base.rb @@ -20,6 +20,10 @@ def self.field_type to_s.split("::").last.underscore end + def self.permitted_attribute(attr, _options = nil) + attr + end + def initialize(attribute, data, page, options = {}) @attribute = attribute @data = data @@ -28,10 +32,6 @@ def initialize(attribute, data, page, options = {}) @options = options end - def self.permitted_attribute(attr, _options = nil) - attr - end - def html_class self.class.html_class end diff --git a/lib/administrate/field/has_one.rb b/lib/administrate/field/has_one.rb index 32cbe60ff1..c8d59186ee 100644 --- a/lib/administrate/field/has_one.rb +++ b/lib/administrate/field/has_one.rb @@ -3,13 +3,6 @@ module Administrate module Field class HasOne < Associative - def nested_form - @nested_form ||= Administrate::Page::Form.new( - resolver.dashboard_class.new, - data || resolver.resource_class.new, - ) - end - def self.permitted_attribute(attr, options = nil) associated_class_name = if options @@ -24,6 +17,13 @@ def self.permitted_attribute(attr, options = nil) { "#{attr}_attributes": related_dashboard_attributes } end + def nested_form + @nested_form ||= Administrate::Page::Form.new( + resolver.dashboard_class.new, + data || resolver.resource_class.new, + ) + end + private def resolver diff --git a/lib/administrate/field/polymorphic.rb b/lib/administrate/field/polymorphic.rb index 22294b5e95..e622542512 100644 --- a/lib/administrate/field/polymorphic.rb +++ b/lib/administrate/field/polymorphic.rb @@ -3,6 +3,10 @@ module Administrate module Field class Polymorphic < BelongsTo + def self.permitted_attribute(attr, _options = nil) + { attr => %i{type value} } + end + def associated_resource_grouped_options classes.map do |klass| [klass.to_s, candidate_resources_for(klass).map do |resource| @@ -11,10 +15,6 @@ def associated_resource_grouped_options end end - def self.permitted_attribute(attr, _options = nil) - { attr => %i{type value} } - end - def permitted_attribute { attribute => %i{type value} } end