app/helpers/umlaut/url_generation.rb in umlaut-3.3.1 vs app/helpers/umlaut/url_generation.rb in umlaut-4.0.0.beta1
- old
+ new
@@ -9,37 +9,18 @@
# Over-ride to allow default forcing of urls with hostnames.
# This is neccesary for our partial_html_sections service
# to work properly. Just set @generate_url_with_host = true
# in your controller, and urls will be generated with hostnames
- # for the remainder of that action.
- def url_for(argument = {})
- if @generate_urls_with_host
- case argument
- when Hash
- # Force only_path = false if not already set
- argument[:only_path] = false if argument[:only_path].nil?
- return super(argument)
- when String
- # We already have a straight string, if it looks relative,
- # absolutize it.
- if argument.starts_with?("/")
- return root_url.chomp("/") + argument
- else
- return super(argument)
- end
- when :back
- return super(argument)
- else
- # polymorphic, we want to force polymorphic_url instead
- # of default polymorphic_path
- return polymorphic_url(argument)
- end
- else
- # @generate_urls_with_host not set, just super
- super(argument)
- end
+ # for the remainder of that action.
+ def url_for(*arguments)
+ url = super
+ if @generate_urls_with_host && url.starts_with?("/")
+ #regex replace trailing slashes or trailing locale if present
+ url = root_url.gsub(/(\/$)?(\/\?.*)?/, '') + url
+ end
+ return url
end
# over-ride path_to_image to generate complete urls with hostname and everything
# if @generate_url_with_host is set. This makes image_tag generate
# src with full url with host. See #url_for
@@ -56,18 +37,18 @@
alias :image_path :path_to_image
# We want stylesheets and javascripts to do the exact same thing,
# magic of polymorphous super() makes it work:
- def path_to_stylesheet(source)
+ def path_to_stylesheet(*args)
path = super
if @generate_urls_with_host
path = request.protocol() + request.host_with_port() + path
end
return path
end
- def path_to_javascript(source)
+ def path_to_javascript(*args)
path = super
if @generate_urls_with_host
path = request.protocol() + request.host_with_port() + path
end
return path