route_translator
route_translator copied to clipboard
Putting an engine in a localized block breaks engine routing method
Assume you have an engine called Blorgh. And you mount it like this:
Rails.application.routes.draw do
localized do
mount Blorgh::Engine, at: '/blorgh'
end
end
It is now impossible to call blorgh.unicorns_path
in a view. Instead of this you have to append the locale like this:
blorgh_en.unicorns_path
I'm on rails 5.0/5.1 and ruby 2.3.x and 2.4.1 and route translator 5.4.0.
Any clues how to fix this?
Thanks in advance!
Bes tregards Roberto
I worked around this adding a method to the application helper like this, but it does not feel right:
module ApplicationHelper
def blorgh
send("blorgh_#{I18n.locale}")
end
end
Refers to #154?
I think so. I remember that discussion. It also had to do with #123 (which was openend by me too ;) )
I'm running into the next problem, even with the "hack" I posted above, the generated urls are missing the locale for the main_app if any engines are mounted at '/'.
Example:
main_app.root_path
should generate /de
, but instead generates /
force_locale is set to true in that example, but it does not seem to matter.
Feel free to submit a PR or start a wiki page explaining the limitation with engines
I had the same problem, that my engine routing proxy was not available anymore and I think I've found a better solution to just add it in an ApplicationHelper
(that worked not good enough for me, cause I found myself hacking this in multiple different classes, just to get this work).
Rails defines these kind of helpers in a module called MountedHelpers
in the https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/route_set.rb
So we can just extend this class on the fly, so in my routes.rb after the route definitions I added something like this:
Rails.application.routes.mounted_helpers.class_eval do
def blorgh
public_send("blorgh_#{I18n.locale}")
end
end
so this is really everywhere accessible where blorgh_en
is for example.
Maybe route_translator
can do this automatically while processing an engine mount?
So this would address at least one of the problems.
Maybe route_translator can do this automatically while processing an engine mount?
I'm not using Route Translator in production in any of my current projects, so a PR with tests and documentation would be very welcomed
PS: because of this issue, I have a development branch where the engine feature has been completely removed
Relevant commit: f70f6f7c8ac96df1b8ec39d5947c2370fd260901
Commit message
The current engine implementation is buggy and incomplete.
We are going to drop the whole feature, waiting for a new contributor
Release 10.0 will still have engine support
I tried, but was not able to write a failing test at the top of the current master. It seems like there were no issues, at least I can not reproduce them in test. But I know we had the issue with the missing routing_proxy helper, but we are using rails 5 in production. Maybe it just works with rails 6?