Created
September 22, 2011 15:45
-
-
Save zdennis/1235106 to your computer and use it in GitHub Desktop.
Rails 3.1 Engine namespaces can creep into URLs in application layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the following route generated in an application layout | |
link_to "Foo", :controller => "foo", :action => "bar" | |
# when rendered from the action of an engine would | |
# try to generate the route | |
link_to "Foo", :controller => "myengine/foo", :action => "bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# routes.rb | |
match '/path' => 'foo#bar', :as => 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if the current controller is "foo/bar/baz" and :controller => "baz/bat" | |
# is specified, the controller becomes "foo/baz/bat" | |
def use_relative_controller! | |
if !named_route && different_controller? | |
old_parts = current_controller.split('/') | |
size = controller.count("/") + 1 | |
parts = old_parts[0...-size] << controller | |
@controller = @options[:controller] = parts.join("/") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment