Module: CanCan::Link::Rest
- Defined in:
- lib/cancan-rest-links/rest_links.rb
Constant Summary collapse
- LINKS =
{ :index => :list, :create => :new, :delete => :destroy, :edit => :update, :show => :read }
Instance Method Summary collapse
- #create_link(object, label = nil) ⇒ Object
- #delete_link(object, options = nil) ⇒ Object
- #edit_link(object, label = nil) ⇒ Object
- #index_link(object, label = nil) ⇒ Object
- #show_link(object, label = nil) ⇒ Object
Instance Method Details
#create_link(object, label = nil) ⇒ Object
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 |
#delete_link(object, options = nil) ⇒ Object
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, = nil) ||= {:label => delete_label, :confirm => confirm_label} case when String label = when Hash label = [:label] confirm_msg = [:confirm] when Array label = [0] confirm_msg = .size > 1 ? [1] : confirm_label end link_to(label, object, :method => :delete, :confirm => confirm_msg) if can?(:destroy, object) end |
#edit_link(object, label = nil) ⇒ Object
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 |
#index_link(object, label = nil) ⇒ Object
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 |
#show_link(object, label = nil) ⇒ Object
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 |