# config.rurequire'bundler/setup'require'action_dispatch'require'action_controller'routes =ActionDispatch::Routing::RouteSet.newroutes.draw do get '/'=>'mainpage#index' get '/page/:id'=>'mainpage#show'endclassMainpageController<ActionController::MetalincludeAbstractController::RenderingincludeActionController::RenderingincludeActionController::ImplicitRenderdefindex# self.response_body = "<h1>Front Page</h1>" @local_var =12345enddefshow self.status =404 self.response_body ="<pre>#{env['action_dispatch.request.path_parameters'] [:id]}</pre>"enddefrender_to_body(*args) template =ERB.newFile.read("#{params[:action]}.html.erb") template.result(binding)endendrun routes
# index.html.erbNumber is: <%= @local_var %>
引进 Action View
# config.rurequire'bundler/setup'require'action_dispatch'require'action_controller'require'action_view'routes =ActionDispatch::Routing::RouteSet.newroutes.draw do get '/'=>'mainpage#index' get '/page/:id'=>'mainpage#show'endclassMainpageController<ActionController::MetalincludeAbstractController::RenderingincludeActionView::RenderingincludeActionController::RenderingincludeActionController::ImplicitRender prepend_view_path('app/views')defindex @local_var =12345enddefshowendenduse ActionDispatch::DebugExceptionsrun routes
# app/views/mainpage/index.html.erbNumber is: <%= @local_var %>
# app/views/mainpage/show.html.erbContent is: <pre><%= env['action_dispatch.request.path_parameters'][:id] %></pre>