diff --git a/app/views/rails_admin/main/_form_filtering_multiselect.html.haml b/app/views/rails_admin/main/_form_filtering_multiselect.html.haml index bf6875e7ae..ed5e0bcd28 100644 --- a/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +++ b/app/views/rails_admin/main/_form_filtering_multiselect.html.haml @@ -41,7 +41,7 @@ - selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv = form.select field.method_name, collection, { :selected => selected_ids, :object => form.object }, field.html_attributes.reverse_merge({:data => { :filteringmultiselect => true, :options => js_data.to_json }, :multiple => true}) -- if authorized? :new, config.abstract_model +- if authorized?(:new, config.abstract_model) && !field.parent_readonly - path_hash = { :model_name => config.abstract_model.to_param, :modal => true } - path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of = link_to " ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "create btn btn-info", :style => 'margin-left:10px' diff --git a/lib/rails_admin/config/fields/types/has_many_association.rb b/lib/rails_admin/config/fields/types/has_many_association.rb index 699b419f70..fe0d0ec680 100644 --- a/lib/rails_admin/config/fields/types/has_many_association.rb +++ b/lib/rails_admin/config/fields/types/has_many_association.rb @@ -17,6 +17,11 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association false end + # read-only parent objects + register_instance_option :parent_readonly do + self.associated_model_config.excluded? + end + def method_name nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids end