Reputation: 16074
In my Rails app I scope locale into my urls:
http://localhost:3000/de/blah/blubb
http://localhost:3000/en/blah/blubb
http://localhost:3000/es/blah/blubb
^^^
How can I "get" the current_url without the locale parameter?
http://localhost:3000/blah/blubb
^^^
At the moment I have this:
<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>
# http://localhost:3000/de/blah/blubb
Upvotes: 0
Views: 876
Reputation: 33626
You can keep a list of available locales you want to exclude:
LOCALES = %w(en de es).map { |l| l.prepend '/' }
Then you can replace them like this:
<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath.sub(Regexp.union(LOCALES), '')}" %>
# /blah/blubb
Upvotes: 1
Reputation: 32933
If you have this pattern
http://localhost:3000/X/blah/blubb
where X can be a locale but can also sometimes be something else, then you will need to specify the list of locales and gsub them out:
"#{request.protocol}#{request.host_with_port}#{request.fullpath.gsub(/^\/#{array_of_locale_strings.map{|s| "(#{s})"}.join("|")}\//,"/")}"
Upvotes: 0