Module: AuthAssistant::ViewHelpers::RestLink
- Included in:
- AuthAssistant::ViewHelpers
- Defined in:
- lib/auth_assistant/view/rest_link.rb
Instance Method Summary collapse
- #create_link(object, label = nil) ⇒ Object (also: #new_link)
- #delete_link(object, options = nil) ⇒ Object (also: #destroy_link)
- #edit_link(object, label = nil) ⇒ Object (also: #update_link)
- #index_link(object, label = nil) ⇒ Object (also: #list_link)
- #index_obj(obj) ⇒ Object
- #show_link(object, label = nil) ⇒ Object (also: #read_link)
Instance Method Details
#create_link(object, label = nil) ⇒ Object Also known as: new_link
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 |
#delete_link(object, options = nil) ⇒ Object Also known as: destroy_link
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, = nil) ||= {:label => auth_labels[:delete], :confirm => auth_labels[:confirm]} case when String label = when Hash label = [:label] confirm_msg = [:confirm] when Array label = [0] confirm_msg = .size > 1 ? [1] : auth_labels[:confirm] end link_to(label, object, :method => :delete, :confirm => confirm_msg) if can?(:destroy, object) end |
#edit_link(object, label = nil) ⇒ Object Also known as: update_link
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 |
#index_link(object, label = nil) ⇒ Object Also known as: list_link
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 |
#show_link(object, label = nil) ⇒ Object Also known as: read_link
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 |