-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make compatible with rails 7.1 (most likely will break for previous v… #87
base: master
Are you sure you want to change the base?
Conversation
I confirm this fixes the issue. @svenfuchs can you please merge and release this as a new major version? I think it's fine to drop support for pre-Rails 7.1 as users can just use older versions of this gem which is very stable. |
@simi can you handle this? |
Can also confirm this helps. if Gem.loaded_specs['routing-filter'].version > Gem::Version.new('0.7')
raise 'Check if PR https://github.com/svenfuchs/routing-filter/pull/87 has been merged and released. If yes, delete this monkey patch.'
end
# We cannot prepend a custom extension module here because we call `super` in this method which should call the Rails
# #find_routes-method and not the routing_filter's #find_routes-method which is broken.
# Instead, we override the whole module definition to fix it.
module ActionDispatchJourneyRouterWithFiltering
def find_routes(env)
path = env.is_a?(Hash) ? env['PATH_INFO'] : env.path_info
filter_parameters = {}
original_path = path.dup
@routes.filters.run(:around_recognize, path, env) do
filter_parameters
end
super(env) do |match, parameters, route|
parameters = parameters.merge(filter_parameters)
if env.is_a?(Hash)
env['PATH_INFO'] = original_path
else
env.path_info = original_path
end
yield [match, parameters, route]
end
end
end This opens the module and overwrites the libary's current implementation within your application. Then add an initializer Dir.glob(Rails.root.join('lib/ext/**/*.rb')).sort.each do |filename|
require filename
end See also: https://makandracards.com/makandra/40730-how-to-organize-monkey-patches-in-ruby-on-rails-projects You cannot use |
Thanks for this fix @nduitz ! It works for me on Rails 7.1.4 - I really hope somebody is able to merge and release this and that the gem has not just become abandonware. |
@simi @svenfuchs please merge this and release as a new major version? |
In case anyone is unable to change their project structure as @begerdom suggests in #87 (comment), you may use the below snippet to override. Just put it in a file under # Removing the (existing) broken find_routes override from the routing-filter gem first
ActionDispatchJourneyRouterWithFiltering.remove_method(:find_routes)
module CustomOverridesActionDispatchJourneyRouterWithFiltering
def find_routes(env)
path = env.is_a?(Hash) ? env['PATH_INFO'] : env.path_info
filter_parameters = {}
original_path = path.dup
@routes.filters.run(:around_recognize, path, env) do
filter_parameters
end
##### OVERRIDE STARTS #####
super(env) do |match, parameters, route|
parameters = parameters.merge(filter_parameters)
if env.is_a?(Hash)
env['PATH_INFO'] = original_path
else
env.path_info = original_path
end
yield [match, parameters, route]
end
##### OVERRIDE ENDS #####
end
end
ActionDispatch::Journey::Router.send(:prepend, CustomOverridesActionDispatchJourneyRouterWithFiltering) |
I think it is good time to sunset this gem actually. I can try to release one of the last versions, but if I understand it properly, same can be achieved with vanilla Rails simply today. Maybe worth to write some migration guide. Is there any public project I can check and migrate and link to it in README? |
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. svenfuchs/routing-filter#87
This seems to work fine in our project for filters to work again with rails >= 7.1.
Maybe I'll have the time to properly implement this with backwards compatibility.
For now this might help others :)
Should address this issue
#83