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

Linking to an engine mounted inside a localized block fails #123

Closed
robotex82 opened this issue Jan 17, 2016 · 5 comments · Fixed by #154
Closed

Linking to an engine mounted inside a localized block fails #123

robotex82 opened this issue Jan 17, 2016 · 5 comments · Fixed by #154
Milestone

Comments

@robotex82
Copy link

When trying to link to an engine, that is mounted inside a localized block, I get following error message:

undefined method `segment_keys' for nil:NilClass

I added a failing test for this situation in my fork in the branch engine-in-localized-block (https://github.com/robotex82/route_translator/tree/engine-in-localized-block).

Can you please help?

Thanks in advance!

Best regards
Roberto

@tagliala
Copy link
Collaborator

I've also seen a fix

Do you mind to submit a PR?

@robotex82
Copy link
Author

Sorry, I haven't found a fix by now. Should I PR the failing test?

@tagliala
Copy link
Collaborator

No, don't worry

Since I don't use the gem this way, I'm asking what is the expected behaviour.

I mean, if I mount an engine in a localized block, what it should happen?

@robotex82
Copy link
Author

Mounting works, but when you try to use url_for or a polymorphic route helper on the engine (i.e. blorgh.posts_path) it throws an error (see my first post).

@robotex82
Copy link
Author

The error ist thrown in https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/routing/mapper.rb

In following method:

      def define_generate_prefix(app, name)
        _route = @set.named_routes.get name
        _routes = @set
        app.routes.define_mounted_helper(name)
        app.routes.extend Module.new {
          def optimize_routes_generation?; false; end
          define_method :find_script_name do |options|
            if options.key? :script_name
              super(options)
            else
              prefix_options = options.slice(*_route.segment_keys)
              prefix_options[:relative_url_root] = ''.freeze
              # we must actually delete prefix segment keys to avoid passing them to next url_for
              _route.segment_keys.each { |k| options.delete(k) }
              _routes.url_helpers.send("#{name}_path", prefix_options)
            end
          end
        }
      end

In following line, *_route is nil, and it should not be:

prefix_options = options.slice(*_route.segment_keys)

tagliala pushed a commit that referenced this issue Dec 15, 2016
Add an expected prefix for engine to avoid method call for nil.

Fix: #123
@tagliala tagliala added this to the 5.0.5 milestone Dec 15, 2016
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

Successfully merging a pull request may close this issue.

2 participants