Module: CanCan::Link::Rest

Defined in:
lib/cancan-rest-links/rest_links.rb

Constant Summary collapse

{
  :index  => :list,
  :create => :new,
  :delete => :destroy,
  :edit   => :update,
  :show   => :read
}

Instance Method Summary collapse

Instance Method Details



12
13
14
15
16
17
# File 'lib/cancan-rest-links/rest_links.rb', line 12

def create_link(object, label = nil)
  label ||= new_label
  obj_name = object_class(object).to_s.downcase
  path = send :"new_#{obj_name}_path"    
  link = link_to(label, path) if can?(:create, object)
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cancan-rest-links/rest_links.rb', line 24

def delete_link(object, options = nil)          
  options ||= {:label => delete_label, :confirm => confirm_label}        
  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] : confirm_label
  end
 link_to(label, object, :method => :delete, :confirm => confirm_msg) if can?(:destroy, object)
end


19
20
21
22
# File 'lib/cancan-rest-links/rest_links.rb', line 19

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


5
6
7
8
9
10
# File 'lib/cancan-rest-links/rest_links.rb', line 5

def index_link(object, label = nil)
  label ||= index_label
  obj = index_obj(object)
  path = send :"#{obj}_path"
  link = link_to(label, path) if can?(:read, object)
end


39
40
41
42
# File 'lib/cancan-rest-links/rest_links.rb', line 39

def show_link(object, label = nil)      
  label ||= show_label
  link_to(label, object) if can?(:read, object)
end