lib/active_admin/resource.rb in activeadmin-1.0.0.pre4 vs lib/active_admin/resource.rb in activeadmin-1.0.0.pre5

- old
+ new

@@ -8,10 +8,11 @@ require 'active_admin/resource/scopes' require 'active_admin/resource/includes' require 'active_admin/resource/scope_to' require 'active_admin/resource/sidebars' require 'active_admin/resource/belongs_to' +require 'active_admin/resource/ordering' module ActiveAdmin # Resource is the primary data storage for resource configuration in Active Admin # @@ -48,10 +49,13 @@ attr_writer :csv_builder # Set breadcrumb builder attr_writer :breadcrumb + #Set order clause + attr_writer :order_clause + # Store a reference to the DSL so that we can dereference it during garbage collection. attr_accessor :dsl # The string identifying a class to decorate our resource with for the view. # nil to not decorate. @@ -80,10 +84,11 @@ include Scopes include Includes include ScopeTo include Sidebars include Routes + include Ordering # The class this resource wraps. If you register the Post model, Resource#resource_class # will point to the Post class def resource_class ActiveSupport::Dependencies.constantize(resource_class_name) @@ -127,10 +132,16 @@ def belongs_to_config @belongs_to end + def belongs_to_param + if belongs_to? && belongs_to_config.required? + belongs_to_config.to_param + end + end + # Do we belong to another resource? def belongs_to? !!belongs_to_config end @@ -141,12 +152,16 @@ def breadcrumb instance_variable_defined?(:@breadcrumb) ? @breadcrumb : namespace.breadcrumb end + def order_clause + @order_clause || namespace.order_clause + end + def find_resource(id) resource = resource_class.public_send *method_for_find(id) - decorator_class ? decorator_class.new(resource) : resource + (decorator_class && resource) ? decorator_class.new(resource) : resource end private def method_for_find(id)