Module: AuthAssistant::ViewHelpers::RestLink

Included in:
AuthAssistant::ViewHelpers
Defined in:
lib/auth_assistant/view/rest_link.rb

Instance Method Summary collapse

Instance Method Details



26
27
28
29
30
# File 'lib/auth_assistant/view/rest_link.rb', line 26

def create_link(object, label = nil)
  label ||= auth_labels[:new] 
  path = send :"new_#{object.class.to_s.downcase}_path"    
  link = link_to(label, path) if can?(:create, object)
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/auth_assistant/view/rest_link.rb', line 37

def delete_link(object, options = nil)    
  options ||= {:label => auth_labels[:delete], :confirm => auth_labels[:confirm]}        
  case options
  when String
    label = options
  when Hash
    label = options[:label]
    confirm_msg = options[:confirm]
  when Array
    label = options[0]
    confirm_msg = options.size > 1 ? options[1] : auth_labels[:confirm]
  end
 link_to(label, object, :method => :delete, :confirm => confirm_msg) if can?(:destroy, object)
end


32
33
34
35
# File 'lib/auth_assistant/view/rest_link.rb', line 32

def edit_link(object, label = nil)
 label ||= auth_labels[:edit]
 link_to(label, [:edit, object]) if can?(:edit, object)
end


4
5
6
7
8
9
10
11
# File 'lib/auth_assistant/view/rest_link.rb', line 4

def index_link(object, label = nil)
  label ||= auth_labels[:index]                   
  puts object.inspect        
  obj = index_obj(object)
  puts "index obj: #{obj.inspect}"   
  path = send :"#{obj}_path"    
  link = link_to(label, path) if can?(:read, object)
end

#index_obj(obj) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/auth_assistant/view/rest_link.rb', line 13

def index_obj(obj)
  o = case obj
  when Array 
    obj.first.class
  when Class
    obj
  else
    obj.class
  end 
  o.name.pluralize.downcase
end


52
53
54
55
56
57
58
59
60
# File 'lib/auth_assistant/view/rest_link.rb', line 52

def show_link(object, label = nil) 
  label ||= auth_labels[:show] 
  if can?(:read, object)
    puts "can read: #{object}"
    link_to(label, object)  
  else
    puts "no link"
  end
end