lib/avo/base_resource.rb in avo-3.0.1.beta19 vs lib/avo/base_resource.rb in avo-3.0.1.beta20
- old
+ new
@@ -242,12 +242,10 @@
@record = record
hydrate_model_with_default_values if @view&.new?
end
- detect_fields
-
unless self.class.model_class.present?
if model_class.present? && model_class.respond_to?(:base_class)
self.class.model_class = model_class.base_class
end
end
@@ -258,13 +256,31 @@
# Used in testing to replace items
if temporary_items.present?
instance_eval(&temporary_items)
else
- fields
+ fetch_fields
end
self
+ end
+
+ def fetch_fields
+ possible_methods_for_view = {
+ index: [:index_fields, :display_fields],
+ show: [:show_fields, :display_fields],
+ edit: [:edit_fields, :form_fields],
+ update: [:edit_fields, :form_fields],
+ new: [:new_fields, :form_fields],
+ create: [:new_fields, :form_fields]
+ }[view.to_sym]
+
+ # Safe navigation operator is used because the view can be "destroy" or "preview"
+ possible_methods_for_view&.each do |method_for_view|
+ return send(method_for_view) if respond_to?(method_for_view)
+ end
+
+ fields
end
def fields
# blank fields method
end