Skip to content

Commit

Permalink
Add inline_edit to HasManyAssociation as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya authored and eliten00b committed Jul 6, 2023
1 parent fbe1fe7 commit b85fc51
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

js_data = {
xhr: xhr,
:'edit-url' => (authorized?(:edit, config.abstract_model) ? edit_path(model_name: config.abstract_model.to_param, id: '__ID__') : ''),
:'edit-url' => (field.inline_edit && authorized?(:edit, config.abstract_model) ? edit_path(model_name: config.abstract_model.to_param, id: '__ID__') : ''),
remote_source: index_path(config.abstract_model, source_object_id: form.object.id, source_abstract_model: source_abstract_model.to_param, associated_collection: field.name, current_action: current_action, compact: true),
sortable: !!field.orderable,
removable: !!field.removable,
Expand Down
8 changes: 8 additions & 0 deletions lib/rails_admin/config/fields/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def association
!!searchable
end

register_instance_option :inline_add do
true
end

register_instance_option :inline_edit do
true
end

# Reader for the association's child model's configuration
def associated_model_config
@associated_model_config ||= RailsAdmin.config(association.klass)
Expand Down
8 changes: 0 additions & 8 deletions lib/rails_admin/config/fields/types/belongs_to_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ class BelongsToAssociation < RailsAdmin::Config::Fields::Association
nested_form ? :form_nested_one : :form_filtering_select
end

register_instance_option :inline_add do
true
end

register_instance_option :inline_edit do
true
end

register_instance_option :eager_load? do
true
end
Expand Down
4 changes: 0 additions & 4 deletions lib/rails_admin/config/fields/types/has_many_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association
false
end

register_instance_option :inline_add do
true
end

def method_name
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
end
Expand Down
8 changes: 0 additions & 8 deletions lib/rails_admin/config/fields/types/has_one_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ class HasOneAssociation < RailsAdmin::Config::Fields::Association
(o = value) && o.send(associated_model_config.object_label_method)
end

register_instance_option :inline_add do
true
end

register_instance_option :inline_edit do
true
end

def editable?
(nested_form || abstract_model.model.new.respond_to?("#{name}_id=")) && super
end
Expand Down

0 comments on commit b85fc51

Please sign in to comment.