link_to_action 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Set of helpers: link_to_new, link_to_edit, link_to_destroy
4
4
 
5
- NOTE: only link_to_new and link_to_edit are available in version 0.0.2
5
+ Bonus helper: link_to_back
6
6
 
7
7
  ## Installation
8
8
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- link_to_{action} object, options
23
+ link_to_{action} object, options
24
24
 
25
25
  ## Contributing
26
26
 
@@ -2,4 +2,7 @@ en:
2
2
  helpers:
3
3
  link_to:
4
4
  new: 'New %{model}'
5
- edit: 'Edit %{model}'
5
+ edit: 'Edit %{model}'
6
+ destroy: 'Delete %{model}'
7
+ destroy_confirm: 'Are you sure?'
8
+ back: 'Back'
@@ -1,3 +1,3 @@
1
1
  module LinkToAction
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -12,17 +12,28 @@ module LinkToAction
12
12
  link_to_action(:edit, object, options)
13
13
  end
14
14
 
15
+ def link_to_destroy(object, options = {})
16
+ options[:method] = :delete
17
+ options[:data] = { :confirm => t(:'helpers.link_to.destroy_confirm') }
18
+ options['data-skip-pjax'] = true
19
+ link_to_action(:destroy, object, options)
20
+ end
21
+
22
+ def link_to_back(options = {})
23
+ ilink_to 'undo large', t(:'helpers.link_to.back'), :back, options
24
+ end
25
+
15
26
  private
16
27
 
17
- ICONS = {new: 'plus', edit: 'edit'}
28
+ ICONS = {new: 'plus', edit: 'edit', destroy: 'trash'}
18
29
 
19
30
  def link_to_action(action, object, options)
20
31
  name = options.delete(:name) || t_action(object, action)
21
32
  params = options.delete(:params) || {}
22
- params[:action] = action
33
+ params[:action] = action if [ :new, :edit ].include? action
23
34
  # TODO: make icon and can? optional
24
35
  ilink_to "#{LinkToAction::ICONS[action]} large", name,
25
- polymorphic_url(object, params), options if can?(action, object)
36
+ polymorphic_path(object, params), options if can?(action, object)
26
37
  end
27
38
 
28
39
  def ilink_to(*args)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_to_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: link_to for specific actions
15
15
  email: