提交 70673759 编写于 作者: A Aaron Patterson

no reason to lazily instantiate the routes

especially if you're just going to add a call two lines down that
populates the cache. common.
上级 b89c5a04
......@@ -25,9 +25,7 @@ class WithMountedEngine < ActionDispatch::IntegrationTest
include Rack::Test::Methods
class BlogEngine < Rails::Engine
def self.routes
@routes ||= begin
routes = ActionDispatch::Routing::RouteSet.new
@routes = ActionDispatch::Routing::RouteSet.new.tap { |routes|
routes.draw do
get "/posts/:id", :to => "inside_engine_generating#show", :as => :post
get "/posts", :to => "inside_engine_generating#index", :as => :posts
......@@ -50,9 +48,10 @@ def self.routes
get "/absolute_custom_root", :to => redirect { |params, request| "/" }
get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" }
end
}
routes
end
def self.routes
@routes
end
def self.call(env)
......@@ -62,9 +61,7 @@ def self.call(env)
end
class RailsApplication
def self.routes
@routes ||= begin
routes = ActionDispatch::Routing::RouteSet.new
@routes = ActionDispatch::Routing::RouteSet.new.tap { |routes|
routes.draw do
scope "/:omg", :omg => "awesome" do
mount BlogEngine => "/blog", :as => "blog_engine"
......@@ -78,9 +75,10 @@ def self.routes
get "/ivar_usage", :to => "outside_engine_generating#ivar_usage"
root :to => "outside_engine_generating#index"
end
}
routes
end
def self.routes
@routes
end
def self.call(env)
......@@ -90,7 +88,6 @@ def self.call(env)
end
# force draw
RailsApplication.routes
RailsApplication.routes.define_mounted_helper(:main_app)
class ::InsideEngineGeneratingController < ActionController::Base
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册