Skip to content

Commit 7cdaeb3

Browse files
committed
Refactor breadcrumbs with support for polymorphic parent relationships
Also, use correct pluralization form (with :other rather than 2).
1 parent 97f1400 commit 7cdaeb3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

app/views/application/_breadcrumbs_and_title.html.slim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
- parent_route_key = parent_model.model_name.singular_route_key
66
- if params["#{parent_route_key}_id"].present?
77
- parent_object = object.try(parent_route_key) || parent_model.find_by(id: params["#{parent_route_key}_id"])
8-
- parent_element = link_to_if(current_user && policy(parent_object).show?, parent_object, {controller: parent_model.model_name.route_key, action: :show, id: parent_object.id})
9-
- parent_root_element = link_to_if(current_user && policy(parent_model).index?, parent_model.model_name.human(count: 2), {controller: parent_model.model_name.route_key, action: :index})
10-
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{parent_route_key}_#{model.model_name.route_key}_path", parent_object))
8+
- parent_element = link_to_if(current_user && policy(parent_object).show?, parent_object, parent_object)
9+
- parent_root_element = link_to_if(current_user && policy(parent_object.class).index?, parent_object.model_name.human(count: :other), parent_object.class)
10+
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: :other), polymorphic_path([parent_object, model]))
1111
- if object
12-
- current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{parent_route_key}_#{model.model_name.singular}_path", parent_object, object))
12+
- current_element = link_to_if(current_user && policy(object).show?, object, polymorphic_path([parent_object, object]))
1313
- else
14-
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index})
14+
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: :other), model)
1515
- if object
16-
- current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id})
16+
- current_element = link_to_if(current_user && policy(object).show?, object, object)
1717
- else
18-
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index})
18+
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: :other), model)
1919
- if object
20-
- current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id})
20+
- current_element = link_to_if(current_user && policy(object).show?, object, object)
2121
- if I18n.exists?("shared.#{params[:action]}")
2222
- active_action = t("shared.#{params[:action]}", model: model&.model_name&.human)
2323
- else
@@ -45,7 +45,7 @@
4545
= current_element
4646
- title = "#{object} - #{title}"
4747
- else
48-
- title = "#{model.model_name.human(count: 2)} - #{title}"
48+
- title = "#{model.model_name.human(count: :other)} - #{title}"
4949
li.breadcrumb-item.active.small
5050
= active_action
5151
- content_for :title, title

0 commit comments

Comments
 (0)