i18n_rails_helpers 1.1.0 → 1.2.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.
@@ -59,10 +59,14 @@ module ContextualLinkHelpers
59
59
  # Use controller name to guess resource or model if not specified
60
60
  case action
61
61
  when :new, :index
62
- model = resource_or_model || controller_name.singularize.camelize.constantize
62
+ default_model = controller_name.singularize.camelize.constantize
63
+ model = resource_or_model || default_model
64
+ explicit_resource_or_model = default_model != model
63
65
  when :show, :edit, :delete
64
- resource = resource_or_model || instance_variable_get("@#{controller_name.singularize}")
66
+ default_resource = instance_variable_get("@#{controller_name.singularize}")
67
+ resource = resource_or_model || default_resource
65
68
  model = resource.class
69
+ explicit_resource_or_model = default_resource != resource
66
70
  end
67
71
  model_name = model.to_s.underscore
68
72
 
@@ -78,19 +82,19 @@ module ContextualLinkHelpers
78
82
  # Path generation
79
83
  case action
80
84
  when :index
81
- if model
85
+ if explicit_resource_or_model
82
86
  path = polymorphic_path(model)
83
87
  else
84
88
  path = url_for(:action => nil)
85
89
  end
86
- when :show, :delete
87
- if resource
90
+ when :delete, :destroy
91
+ if explicit_resource_or_model
88
92
  path = polymorphic_path(resource)
89
93
  else
90
- return
94
+ path = url_for(:action => :destroy)
91
95
  end
92
96
  else
93
- if resource_or_model
97
+ if explicit_resource_or_model
94
98
  path = polymorphic_path(resource_or_model, :action => action)
95
99
  else
96
100
  path = url_for(:action => action)
@@ -1,3 +1,3 @@
1
1
  module I18nRailsHelpers
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_rails_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
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: 2014-03-03 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rails i18n view helpers for things like crud actions, models and and
15
15
  attributes.