This repository has been archived by the owner on Nov 17, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
init.rb
48 lines (42 loc) · 1.77 KB
/
init.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
45
46
47
48
# Copyright (c) 2006 Matthew Draper
# Released under the MIT License. See the LICENSE file for more details.
require 'auto_admin'
class ActionController::Routing::RouteSet
alias draw_without_admin draw
def draw_with_admin
draw_without_admin do |map|
prefix = AutoAdmin::AutoAdminConfiguration.url_prefix rescue 'admin'
map.connect "#{prefix}", :controller => 'auto_admin', :action => 'index'
map.connect "#{prefix}/asset/*path", :controller => 'auto_admin', :action => 'asset'
map.connect "#{prefix}/-/:action/:id", :controller => 'auto_admin', :action => 'index',
:requirements => { :model => nil }
map.connect "#{prefix}/:model/:action", :controller => 'auto_admin', :action => 'list',
:requirements => { :action => /[^0-9].*/, :id => nil }
map.connect "#{prefix}/:model.:format", :controller => 'auto_admin', :action => 'list'
map.connect "#{prefix}/:model/:id/:action", :controller => 'auto_admin', :action => 'edit',
:requirements => { :id => /\d+/ }
yield map
end
end
alias draw draw_with_admin
end
class ::Object
def to_label
return label if respond_to? :label
return name if respond_to? :name
return to_s if respond_to? :to_s
inspect
end
end
# We want AssociationProxy to forward #to_label on to its target, but
# because we're adding the above to Object after AssociationProxy
# flushes its instance methods, we have to do it manually.
begin
ActiveRecord::Associations::AssociationProxy.send :undef_method, :to_label
rescue NameError
# Nothing to do, really!
end
class ::Array; def to_label; map {|m| m.to_label }.join(', '); end; end
class ::TrueClass; def to_label; 'Yes'; end; end
class ::FalseClass; def to_label; 'No'; end; end
class ::NilClass; def to_label; '(none)'; end; end