i18n_rails_helpers 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/list_link_helpers.rb +14 -11
- metadata +2 -2
data/lib/list_link_helpers.rb
CHANGED
@@ -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 =
|
24
|
+
model = main_resource_or_model || controller_name.singularize.camelize.constantize
|
18
25
|
when 'show', 'edit', 'delete'
|
19
|
-
resource =
|
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 '
|
30
|
-
return list_link_to(action,
|
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,
|
37
|
-
|
38
|
-
return list_link_to(action,
|
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
|
|