我的 Rails 路由有一个奇怪的问题。我有一个名为 Page 的控制器和一个名为 Page#dashboard 的方法
当我尝试访问 /dashboard/1 时,页面控制器的仪表板方法永远不会被执行。但令人惊讶的是 /pages/dashboard.html.erb 渲染得很好。
有人可以解释一下为什么吗?
代码详情如下。谢谢
试图访问 -/dashboard/1
路由.rb
match '/dashboard/:id' => 'page#dashboard'
Page_Controller.rb
class PageController < ApplicationController
before_filter :init
private
def init
puts "init getting executed !!!!!!!!!" #this gets printed on console
end
def dashboard
puts "dashboard getting executed !!!!!!!!!" #this doesnt get printed on console
end
end
viewPage - 页面/dashboard.html.erb
日志如下所示 -
init getting executed !!!!!!!!!
Started GET "/dashboard/8" for 127.0.0.1 at 2012-06-03 00:04:40 +0800
Processing by PageController#dashboard as HTML
Parameters: {"id"=>"8"}
Rendered page/dashboard.html.erb within layouts/page (45.9ms)
Completed 200 OK in 180ms (Views: 133.6ms | ActiveRecord: 3.1ms)