aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorTeddy Wing2017-07-03 18:29:41 +0200
committerTeddy Wing2017-07-06 12:30:59 +0200
commit2d26c10de73fd6bfbf575dafee7b72e97844ff6b (patch)
tree518e9f21579e09520509bff04c3705a73d5af35b /app/helpers
parentae70f880cc1e74b242938734ba31498352a548f0 (diff)
downloadchouette-core-2d26c10de73fd6bfbf575dafee7b72e97844ff6b.tar.bz2
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
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/table_builder_helper.rb5
-rw-r--r--app/helpers/table_builder_helper/custom_links.rb5
-rw-r--r--app/helpers/table_builder_helper/url.rb7
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