Skip to content

Instantly share code, notes, and snippets.

@ericallam
Created November 9, 2011 15:23
Show Gist options
  • Save ericallam/1351762 to your computer and use it in GitHub Desktop.
Save ericallam/1351762 to your computer and use it in GitHub Desktop.
Add routes outside of routes.draw
# Unfortunately, you still have to create the routes somewhere in routes.rb
Your::Application.routes.draw do
root :to => 'controller#action'
end
mapper = ActionDispatch::Routing::Mapper.new(Rails.application.routes)
mapper.instance_exec do
match '/some/action' => "some#action"
end
@ilyakatz
Copy link

ilyakatz commented Dec 9, 2011

Hey, there. I came across this gist when trying to add a new route. Basically, I want to add a route that is only used in test environment and thought this would be perfect. However, when I tried it didn't work (rails 3.0.9)

Inside

RouteSet#add_route

the variable

@valid_conditions

Is set to nil when the routeset is frozen. Any ideas if it is possible to unfreeze it. Or will I need to reinitialize? Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment