Commit 4398fe05d69af222346f2daaae43e4304ff17df4
1 parent
692325d6
Exists in
staging
and in
42 other branches
Generalizing partial_for_class to for tasks too
Showing
2 changed files
with
6 additions
and
17 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -263,9 +263,9 @@ module ApplicationHelper |
263 | 263 | |
264 | 264 | VIEW_EXTENSIONS = %w[.rhtml .html.erb] |
265 | 265 | |
266 | - def partial_for_class_in_view_path(klass, view_path) | |
266 | + def partial_for_class_in_view_path(klass, view_path, suffix = nil) | |
267 | 267 | return nil if klass.nil? |
268 | - name = klass.name.underscore | |
268 | + name = [klass.name.underscore, suffix].compact.map(&:to_s).join('_') | |
269 | 269 | |
270 | 270 | search_name = String.new(name) |
271 | 271 | if search_name.include?("/") |
... | ... | @@ -283,28 +283,17 @@ module ApplicationHelper |
283 | 283 | partial_for_class_in_view_path(klass.superclass, view_path) |
284 | 284 | end |
285 | 285 | |
286 | - def partial_for_class(klass) | |
286 | + def partial_for_class(klass, suffix=nil) | |
287 | 287 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? |
288 | 288 | name = klass.name.underscore |
289 | 289 | @controller.view_paths.each do |view_path| |
290 | - partial = partial_for_class_in_view_path(klass, view_path) | |
290 | + partial = partial_for_class_in_view_path(klass, view_path, suffix) | |
291 | 291 | return partial if partial |
292 | 292 | end |
293 | 293 | |
294 | 294 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' |
295 | 295 | end |
296 | 296 | |
297 | - def partial_for_task_class(klass, action) | |
298 | - raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | |
299 | - | |
300 | - name = "#{klass.name.underscore}_#{action.to_s}" | |
301 | - VIEW_EXTENSIONS.each do |ext| | |
302 | - return name if File.exists?(File.join(RAILS_ROOT, 'app', 'views', params[:controller], '_'+name+ext)) | |
303 | - end | |
304 | - | |
305 | - partial_for_task_class(klass.superclass, action) | |
306 | - end | |
307 | - | |
308 | 297 | def view_for_profile_actions(klass) |
309 | 298 | raise ArgumentError, 'No profile actions view for this class.' if klass.nil? |
310 | 299 | ... | ... |
app/views/tasks/_task.rhtml
... | ... | @@ -50,13 +50,13 @@ |
50 | 50 | <% fields_for "tasks[#{task.id}][task]", task do |f| %> |
51 | 51 | <% if task.accept_details %> |
52 | 52 | <div id="on-accept-information-<%=task.id%>" style="display: none"> |
53 | - <%= render :partial => partial_for_task_class(task.class, :accept_details), :locals => {:task => task, :f => f} %> | |
53 | + <%= render :partial => partial_for_class(task.class, :accept_details), :locals => {:task => task, :f => f} %> | |
54 | 54 | </div> |
55 | 55 | <% end %> |
56 | 56 | |
57 | 57 | <% if task.reject_details %> |
58 | 58 | <div id="on-reject-information-<%=task.id%>" style="display: none"> |
59 | - <%= render :partial => partial_for_task_class(task.class, :reject_details), :locals => {:task => task, :f => f} %> | |
59 | + <%= render :partial => partial_for_class(task.class, :reject_details), :locals => {:task => task, :f => f} %> | |
60 | 60 | </div> |
61 | 61 | <% end %> |
62 | 62 | <% end %> | ... | ... |