Skip to content

Instantly share code, notes, and snippets.

@zdennis
Created September 22, 2011 15:45
Show Gist options
  • Save zdennis/1235106 to your computer and use it in GitHub Desktop.
Save zdennis/1235106 to your computer and use it in GitHub Desktop.
Rails 3.1 Engine namespaces can creep into URLs in application layout
# 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"
# routes.rb
match '/path' => 'foo#bar', :as => 'foo'
# 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