-
Notifications
You must be signed in to change notification settings - Fork 11
/
base.rb
44 lines (37 loc) · 1.25 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Base methods for CRUD actions
# Simply override any methods in your action controller you want to be customised
# Don't forget to add:
# resources :plural_model_name_here
# to your routes.rb file.
# Full documentation about CRUD and resources start here:
# -> http://www.google.com/search?q=rails%20REST
# Example (add to your controller):
# crudify :foo, { :title_attribute => 'name' }
module Crudify
module Base
def self.default_options(model_name)
singular_name = model_name.to_s
class_name = singular_name.camelize
plural_name = singular_name.pluralize
this_class = class_name.constantize
{
:title_attribute => "title",
:use_class_name_as_title => false,
:paginate => true,
:sortable => true,
:searchable => true,
:include => [],
:order => ('position ASC' if this_class.table_exists? && this_class.column_names.include?('position')),
:conditions => '',
:search_conditions => '',
:redirect_to_url => "admin_#{plural_name}_url",
:log => Rails.env == 'development'
}
end
def self.append_features(base)
super
base.send(:include, Crudify::HookMethods)
base.extend(Crudify::ClassMethods)
end
end
end