casey_jones 0.0.108 → 0.0.109

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,15 +17,57 @@ module ActsAsLinkable
17
17
  obj_name = (p[:object_name] ||= obj.class.name.underscore).to_s.to_sym
18
18
  (render :partial => p[:partial], :locals => {obj_name => obj}).strip
19
19
  else
20
- name = obj.link_attr[:name]
21
- link_attr.except(:name).each do |key, val|
22
- html_options[key] ||= obj.send(val) if val.class==Symbol
20
+ name = obj.send(obj.link_attr[:name])
21
+ obj.link_attr.except(:name).each do |key, val|
22
+ html_options[key] ||= ((val.class==Symbol) ? obj.send(val) : val)
23
23
  end
24
- url = self.send("#{obj.class.name.tableize}_path", obj, options.except(:remote))
25
- link_to name, obj, html_options, :remote => options[:remote]||true
24
+ link_obj = options.empty? ? obj : self.send("#{obj.class.name.tableize}_path", obj, options.except(:remote))
25
+ link_to name, link_obj, html_options, :remote => (options[:remote]||true)
26
26
  end
27
27
  end
28
28
  end
29
+ def index_link(controller, name=nil, options={}, html_options={})
30
+ name ||= controller.titleize
31
+ url = self.send("#{controller}_path", options.except(:remote))
32
+ html_options[:remote] ||= true
33
+ link_to name, url, html_options
34
+ end
35
+
36
+ def new_link(klass, name=nil, options={}, html_options={})
37
+ name ||= "New #{klass.name.titleize}"
38
+ if can? :create, klass
39
+ url = self.send("new_#{klass.name.underscore}_path", options.except(:remote))
40
+ html_options[:remote] ||= true
41
+ link_to name, url, html_options
42
+ end
43
+ end
44
+
45
+ def show_link(resource, name='Show', options={}, html_options={})
46
+ if can? :read, resource
47
+ url = self.send("#{resource.class.name.underscore}_path", resource, options.except(:remote))
48
+ html_options[:remote] ||= true
49
+ link_to name, url, html_options
50
+ else
51
+ name
52
+ end
53
+ end
54
+
55
+ def edit_link(resource, name='Edit', options={}, html_options={})
56
+ if can? :edit, resource
57
+ url = self.send("edit_#{resource.class.name.underscore}_path", resource, options.except(:remote))
58
+ html_options[:remote] ||= true
59
+ link_to name, url, html_options
60
+ end
61
+ end
62
+
63
+ def destroy_link(resource, name='Delete', options={}, html_options={})
64
+ if can? :destroy, resource
65
+ html_options["data-confirm"] ||= "Really delete this #{resource.class.name.titleize}?"
66
+ html_options[:remote] ||= true
67
+ html_options[:method] |= :delete
68
+ link_to name, resource, html_options
69
+ end
70
+ end
29
71
  end
30
72
  end
31
73
  ActiveRecord::Base.extend(ActsAsLinkable::ActiveRecordExtensions)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casey_jones
3
3
  version: !ruby/object:Gem::Version
4
- hash: 199
4
+ hash: 197
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 108
10
- version: 0.0.108
9
+ - 109
10
+ version: 0.0.109
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyler Gannon