lib/active_admin/resource.rb in activeadmin-1.0.0.pre5 vs lib/active_admin/resource.rb in activeadmin-1.0.0
- old
+ new
@@ -1,6 +1,7 @@
require 'active_admin/resource/action_items'
+require 'active_admin/resource/attributes'
require 'active_admin/resource/controllers'
require 'active_admin/resource/menu'
require 'active_admin/resource/page_presenters'
require 'active_admin/resource/pagination'
require 'active_admin/resource/routes'
@@ -51,10 +52,13 @@
# Set breadcrumb builder
attr_writer :breadcrumb
#Set order clause
attr_writer :order_clause
+ # Display create another checkbox on a new page
+ # @return [Boolean]
+ attr_writer :create_another
# 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.
@@ -85,10 +89,11 @@
include Includes
include ScopeTo
include Sidebars
include Routes
include Ordering
+ include Attributes
# 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)
@@ -124,11 +129,11 @@
controller.instance_methods.map(&:to_sym) & ResourceController::ACTIVE_ADMIN_ACTIONS
end
def belongs_to(target, options = {})
@belongs_to = Resource::BelongsTo.new(self, target, options)
- self.navigation_menu_name = target unless @belongs_to.optional?
+ self.menu_item_options = false if @belongs_to.required?
controller.send :belongs_to, target, options.dup
end
def belongs_to_config
@belongs_to
@@ -156,28 +161,46 @@
def order_clause
@order_clause || namespace.order_clause
end
+ def create_another
+ instance_variable_defined?(:@create_another) ? @create_another : namespace.create_another
+ end
+
def find_resource(id)
resource = resource_class.public_send *method_for_find(id)
(decorator_class && resource) ? decorator_class.new(resource) : resource
end
+ def resource_columns
+ resource_attributes.values
+ end
+
+ def resource_attributes
+ @resource_attributes ||= default_attributes
+ end
+
+ def association_columns
+ @association_columns ||= resource_attributes.select{ |key, value| key != value }.values
+ end
+
+ def content_columns
+ @content_columns ||= resource_attributes.select{ |key, value| key == value }.values
+ end
+
private
def method_for_find(id)
if finder = resources_configuration[:self][:finder]
[finder, id]
- elsif Rails::VERSION::MAJOR >= 4
- [:find_by, { resource_class.primary_key => id }]
else
- [:"find_by_#{resource_class.primary_key}", id]
+ [:find_by, { resource_class.primary_key => id }]
end
end
def default_csv_builder
- @default_csv_builder ||= CSVBuilder.default_for_resource(resource_class)
+ @default_csv_builder ||= CSVBuilder.default_for_resource(self)
end
end # class Resource
end # module ActiveAdmin