app/models/para/component/crud.rb in para-0.5.4 vs app/models/para/component/crud.rb in para-0.6.2

- old
+ new

@@ -11,10 +11,12 @@ configurable_on :namespaced has_many :component_resources, class_name: 'Para::ComponentResource', foreign_key: :component_id, autosave: true, dependent: :destroy + before_validation :ensure_model_type + def namespaced? case namespaced when 'true' then true else false end @@ -30,18 +32,33 @@ def remove_resource(resource) component_resources.where(resource: resource).first.destroy end + def update_with(attributes) + # If no model_type is provided in the configuration file, default to + # the singular and camelized version of the identifier, allowing to + # create crud components without setting the :model_type option, when + # given a conventional name + attributes[:model_type] ||= identifier.to_s.camelize.singularize if identifier + attributes[:controller] ||= '/para/admin/crud_resources' + + super + end + private def namespaced_resources model.joins( "INNER JOIN para_component_resources ON " + "para_component_resources.resource_id = #{ model_table_name }.id" ).where( para_component_resources: { component_id: id } ) + end + + def ensure_model_type + self.model_type ||= identifier end end end end