i18n_rails_helpers 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,11 +48,9 @@ module ContextualLinkHelpers
48
48
  end
49
49
  end
50
50
 
51
- def contextual_link_to(action, options = {})
52
- # We don't want to change the passed in options
53
- options = options.dup
54
-
55
- resource_or_model = options.delete(:resource) || options.delete(:model)
51
+ def contextual_link_to(action, resource_or_model = nil, link_options = {})
52
+ # We don't want to change the passed in link_options
53
+ options = link_options.dup
56
54
 
57
55
  # Handle both symbols and strings
58
56
  action = action.to_sym
@@ -81,34 +79,37 @@ module ContextualLinkHelpers
81
79
  options.merge!(:confirm => t_confirm_delete(resource), :method => :delete)
82
80
  end
83
81
 
84
- # Path generation
85
- case action
86
- when :index
87
- if explicit_resource_or_model
88
- path = polymorphic_path(model)
89
- else
90
- path = url_for(:action => nil)
91
- end
92
- when :delete, :destroy
93
- if explicit_resource_or_model
94
- path = polymorphic_path(resource)
95
- else
96
- path = url_for(:action => :destroy)
97
- end
98
- else
99
- if explicit_resource_or_model
100
- path = polymorphic_path(resource_or_model, :action => action)
82
+ begin
83
+ # Path generation
84
+ case action
85
+ when :index
86
+ if explicit_resource_or_model
87
+ path = polymorphic_path(model)
88
+ else
89
+ path = url_for(:action => nil)
90
+ end
91
+ when :delete, :destroy
92
+ if explicit_resource_or_model
93
+ path = polymorphic_path(resource)
94
+ else
95
+ path = url_for(:action => :destroy)
96
+ end
101
97
  else
102
- path = url_for(:action => action)
98
+ if explicit_resource_or_model
99
+ path = polymorphic_path(resource_or_model, :action => action)
100
+ else
101
+ path = url_for(:action => action)
102
+ end
103
103
  end
104
- end
105
104
 
106
- return icon_link_to(action, path, options)
107
- end
105
+ return icon_link_to(action, path, options)
108
106
 
109
- def contextual_links_for(options = {})
110
- action = options.delete(:action)
107
+ rescue ActionController::UrlGenerationError
108
+ # This handles cases where we did exclude crud actions in the routing map.
109
+ end
110
+ end
111
111
 
112
+ def contextual_links_for(action = nil, resource_or_model = nil, options = {})
112
113
  # Use current action if not specified
113
114
  action ||= action_name
114
115
 
@@ -127,14 +128,14 @@ module ContextualLinkHelpers
127
128
  actions << :new
128
129
  end
129
130
 
130
- links = actions.map{|link_for| contextual_link_to(link_for, options)}
131
+ links = actions.map{|link_for| contextual_link_to(link_for, resource_or_model, options)}
131
132
 
132
133
  return links.join("\n").html_safe
133
134
  end
134
135
 
135
- def contextual_links(options = {}, &block)
136
+ def contextual_links(action = nil, resource_or_model = nil, options = {}, &block)
136
137
  content_tag('div', :class => I18nRailsHelpers.contextual_class) do
137
- content = contextual_links_for(options)
138
+ content = contextual_links_for(action, resource_or_model, options)
138
139
  if block_given?
139
140
  additional_content = capture(&block)
140
141
  content += ("\n" + additional_content).html_safe
@@ -1,3 +1,3 @@
1
1
  module I18nRailsHelpers
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
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.3.0
4
+ version: 1.3.1
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-04-22 00:00:00.000000000 Z
12
+ date: 2014-05-27 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.