From 2d26c10de73fd6bfbf575dafee7b72e97844ff6b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 3 Jul 2017 18:29:41 +0200 Subject: TableBuilderHelper::URL: Inject `current_referential` dependency Turns out the only reason why this code worked before was because the only place I was using `table_builder_2` was for a list of `Referential`s, and there's an explicit check for `item.is_a?(Referential)` that avoids calling `current_referential`. Otherwise, when that `unless` condition passes, we get a failure because `current_referential` can't be found. It can't be found because helper methods are not accessible in this scope (duh). In order to make the referential accessible to the method, require one as an argument. Now we explicitly pass the `current_referential` from places where `#polymorphic_url_parts` is called. Refs #3479 --- app/helpers/table_builder_helper.rb | 5 ++++- app/helpers/table_builder_helper/custom_links.rb | 5 ++++- app/helpers/table_builder_helper/url.rb | 7 +++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index b93e9b22b..d748ec33a 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -122,7 +122,10 @@ module TableBuilderHelper if column_is_linkable?(column) # Build a link to the `item` - polymorph_url = URL.polymorphic_url_parts(item) + polymorph_url = URL.polymorphic_url_parts( + item, + current_referential + ) bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir') else bcont << content_tag(:td, value) diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb index abb907678..39cffd2cd 100644 --- a/app/helpers/table_builder_helper/custom_links.rb +++ b/app/helpers/table_builder_helper/custom_links.rb @@ -31,7 +31,10 @@ module TableBuilderHelper polymorph_url << action end - polymorph_url += URL.polymorphic_url_parts(@obj) + polymorph_url += URL.polymorphic_url_parts( + @obj, + @user_context.context[:referential] + ) end def method_for_action(action) diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index f60864ac1..894e5ddf8 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -1,12 +1,11 @@ module TableBuilderHelper - # Depends on `current_referential`, defined in object controllers class URL - def self.polymorphic_url_parts(item) + def self.polymorphic_url_parts(item, referential) polymorph_url = [] unless item.is_a?(Calendar) || item.is_a?(Referential) - if current_referential - polymorph_url << current_referential + if referential + polymorph_url << referential polymorph_url << item.line if item.respond_to? :line polymorph_url << item.route.line if item.is_a?(Chouette::RoutingConstraintZone) polymorph_url << item if item.respond_to? :line_referential -- cgit v1.2.3