i18n_rails_helpers 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/list_link_helpers.rb +14 -11
  2. metadata +2 -2
@@ -11,12 +11,19 @@ module ListLinkHelpers
11
11
  action = action.to_s
12
12
 
13
13
  # Resource and Model setup
14
+ # Support nested resources
15
+ if resource_or_model.is_a? Array
16
+ main_resource_or_model = resource_or_model.first
17
+ else
18
+ main_resource_or_model = resource_or_model
19
+ end
20
+
14
21
  # Use controller name to guess resource or model if not specified
15
22
  case action
16
23
  when 'new', 'index'
17
- model = resource_or_model || controller_name.singularize.camelize.constantize
24
+ model = main_resource_or_model || controller_name.singularize.camelize.constantize
18
25
  when 'show', 'edit', 'delete'
19
- resource = resource_or_model || instance_variable_get("@#{controller_name.singularize}")
26
+ resource = main_resource_or_model || instance_variable_get("@#{controller_name.singularize}")
20
27
  model = resource.class
21
28
  end
22
29
  model_name = model.to_s.underscore
@@ -26,16 +33,12 @@ module ListLinkHelpers
26
33
 
27
34
  # Link generation
28
35
  case action
29
- when 'new'
30
- return list_link_to(action, send("new_#{model_name}_path"))
31
- when 'show'
32
- return list_link_to(action, send("#{model_name}_path", resource))
33
- when 'edit'
34
- return list_link_to(action, send("edit_#{model_name}_path", resource))
36
+ when 'index', 'show'
37
+ return list_link_to(action, polymorphic_path(resource_or_model))
35
38
  when 'delete'
36
- return list_link_to(action, send("#{model_name}_path", resource), :confirm => t_confirm_delete(resource), :method => :delete)
37
- when 'index'
38
- return list_link_to(action, send("#{model_name.pluralize}_path"))
39
+ return list_link_to(action, polymorphic_path(resource_or_model), :confirm => t_confirm_delete(resource), :method => :delete)
40
+ else
41
+ return list_link_to(action, polymorphic_path(resource_or_model, :action => action))
39
42
  end
40
43
  end
41
44
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 11
7
+ - 12
8
8
  - 0
9
- version: 0.11.0
9
+ version: 0.12.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Simon H\xC3\xBCrlimann"