lib/avo/base_resource.rb in avo-2.11.1 vs lib/avo/base_resource.rb in avo-2.11.2.pre.1
- old
+ new
@@ -45,10 +45,11 @@
class_attribute :hide_from_global_search, default: false
class_attribute :after_create_path, default: :show
class_attribute :after_update_path, default: :show
class_attribute :record_selector, default: true
class_attribute :keep_filters_panel_open, default: false
+ class_attribute :extra_params
class << self
delegate :t, to: ::I18n
delegate :context, to: ::Avo::App
@@ -249,26 +250,40 @@
get_field_definitions.select do |field|
[Avo::Fields::FileField, Avo::Fields::FilesField].include? field.class
end
end
- def fill_model(model, params)
+ def fill_model(model, params, extra_params: [])
# Map the received params to their actual fields
fields_by_database_id = get_field_definitions
.reject do |field|
field.computed
end
.map do |field|
[field.database_id(model).to_s, field]
end
.to_h
+ # Write the field values
params.each do |key, value|
field = fields_by_database_id[key]
next unless field.present?
model = field.fill_field model, key, value, params
+ end
+
+ # Write the user configured extra params to the model
+ if extra_params.present?
+ extra_params.each do |param_id|
+ # if it's a nested array, use the key
+ param_id = param_id.first.first if param_id.is_a? Hash
+
+ next unless @model.respond_to? "#{param_id}="
+
+ param_value = params[param_id]
+ @model.send("#{param_id}=", param_value)
+ end
end
model
end