Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Changing scope in a mounted engine #6854

Closed
wants to merge 1 commit into from

4 participants

@sigmike

Within an engine mounted in a dynamic scope, I'm trying to make an link to the same action but another scope (ie. changing the dynamic part of the scope) and it doesn't work.

I need this to build a link to the current page in another locale. The scope defines the locale, and the current page is handled by the engine.

I wrote a failing test to demonstrate the current behavior, which doesn't work. Rails generates an URL with the new scope in the query string, and the old scope in the path.

Is there another way to change the dynamic scope inside the engine ?
Or is this a bug that should be fixed ?

The output is:
"/more-awesomeness/blog/link_to_another_scope" expected but was
"/some-awesomeness/blog/link_to_another_scope?omg=more-awesomeness"

@josevalim
Owner
@drogus
Collaborator

I'm not sure if we can fix that. Engine's routes don't know anything about the way the engine is mounted. In other words you need to call router from the host, typically main application, to generate such route.

If this is an engine that is rather mounted only in your app, you could use main_app helper, like main_app.url_for(:omg => "something"). If this is an engine that's more generic and you expect that it could be mounted in other engine, you could allow to configure the name of the helper (so you can use something else than main_app).

I will leave this open for a while, in case someone has any idea on better way to do it, but I think it's a "won't fix"

@steveklabnik
Collaborator

It's been 5 months, so I'm closing this as wontfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 25, 2012
  1. @sigmike
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +10 −0 actionpack/test/dispatch/prefix_generation_test.rb
View
10 actionpack/test/dispatch/prefix_generation_test.rb
@@ -31,6 +31,7 @@ def self.routes
match "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine"
match "/conflicting_url", :to => "inside_engine_generating#conflicting"
match "/foo", :to => "never#invoked", :as => :named_helper_that_should_be_invoked_only_in_respond_to_test
+ match "/link_to_another_scope", :to => "inside_engine_generating#link_to_another_scope", :as => :link_to_another_scope
end
routes
@@ -100,6 +101,10 @@ def polymorphic_path_for_engine
def conflicting
render :text => "engine"
end
+
+ def link_to_another_scope
+ render :text => url_for(:omg => "more-awesomeness", :only_path => true)
+ end
end
class ::OutsideEngineGeneratingController < ActionController::Base
@@ -188,6 +193,11 @@ def setup
assert_equal "engine", last_response.body
end
+ test "[ENGINE] link to another scope" do
+ get "/some-awesomeness/blog/link_to_another_scope"
+ assert_equal "/more-awesomeness/blog/link_to_another_scope", last_response.body
+ end
+
# Inside Application
test "[APP] generating engine's route includes prefix" do
get "/generate"
Something went wrong with that request. Please try again.