Skip to content
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

Rails 4: around_generate sometimes not being called #47

Open
til opened this issue May 25, 2013 · 6 comments
Open

Rails 4: around_generate sometimes not being called #47

til opened this issue May 25, 2013 · 6 comments

Comments

@til
Copy link

til commented May 25, 2013

With the following setup on rails 4, the around_generate method is not called for url helper methods such as products_path. It is being called as expected for an equivalent url_for call though.

module RoutingFilter
  class Translate < Filter
    ...
    def around_generate(params, &block)
      yield.tap do |result|
        puts 'should be called'
      end
    end
  end
end

MyApp::Application.routes.draw do
  filter :translate
  resources :products
end

products_path # => around_generate was not called
url_for(controller: 'products', action: 'index') # => around_generate was called

It seems to be related to optimized url helper methods, and the following monkey patch makes RoutingFilter behave as expected:

ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.class_eval do
  def self.optimize_helper?(route)
    false
  end
end

I don't understand the rails routing internals enough to know what's going on here, but hope there's a better solution than this monkey patch.

@dark-panda
Copy link

I am seeing this behaviour as well. This appears to occur OptimizedUrlHelper calls ActionDispatch::Http::URL.url_for directly rather than through ActionDispatch::Routing::RouteSet#url_for, which in turn the generate method that routing-filter hooks into. OptimizedUrlHelper bypasses that generate call altogether and skips right to ActionDispatch::Http::URL.url_for.

@brega
Copy link

brega commented Jan 20, 2014

+1

1 similar comment
@brett-bender
Copy link

+1

@aripollak
Copy link

Two other options:

  • If you populate default_url_options, the optimized url helper is not used.
  • You can define optimize_routes_generation? on your controller(s) to decide dynamically whether or not the routing filter can be skipped.

@debreczeni
Copy link

👍

@alepore
Copy link

alepore commented Jan 22, 2016

related: rails/rails#12178

mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Aug 17, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Aug 26, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Sep 5, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Sep 6, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Sep 15, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Sep 15, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Oct 3, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
crowbot pushed a commit to mysociety/alaveteli that referenced this issue Oct 25, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Nov 24, 2016
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 16, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 16, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 22, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 23, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
lizconlan pushed a commit to mysociety/alaveteli that referenced this issue Feb 28, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
lizconlan pushed a commit to mysociety/alaveteli that referenced this issue Feb 28, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 28, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Feb 28, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Mar 1, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
mysociety-pusher pushed a commit to mysociety/alaveteli that referenced this issue Mar 16, 2017
> When there's an optional scope, `link_to resource` doesn't seem to work
> properly in rails 4

The fix was taken from https://git.io/v6otV. It looks like this is still
an issue, so we might want to extract this monkeypatch out in to its own
file if it's still broken by the time we get to Rails 4.2.

- svenfuchs/routing-filter#47
- rails/rails#12178
- rails/rails#22767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants