我刚刚通过观看railscasts升级到rails 3.1.0和3.2.0来升级rails 3.0.9应用程序到rails 3.2.1。更新前我(当时的工作)的routes.rb文件看起来像:使用导轨进行路由3.2.1
match "home" => "pages#index"
match "*page" => "pages#show"
root :to => "pages#index"
我改变了我的routes.rb文件更新后:
match "home" => "pages#index"
match "pages/*page" => "pages#show", :format => false
root :to => "pages#index"
我在溃败了这个想法从Ruby on Rails routing Globbing部分,以模仿rails 3.0.x.现在
当我我的链接,通过呈现在点击:
<li><%= link_to "What We Do", "/what-we-do" %></li>
我得到这个错误:
Routing Error
No route matches [GET] "/what-we-do"
Try running rake routes for more information on available routes.
rake routes produces:
home /home(.:format) pages#index
/pages/*page pages#show
root/ pages#index
If that is helpful.
我试图渲染页面叫什么,我们-do.html .erb,位于app/views/pages。
,这是我的控制器:
class PagesController < ApplicationController
def index
render :home, :layout => false
end
def show
render static_page
rescue
# page_not_found
end
private
def static_page
"#{RAILS_ROOT}/app/views/pages/#{params[:page]}.html.erb"
end
def page_not_found
render "#{Rails.root}/public/404.html", :layout => false
end
end
任何人有什么建议?
。我把我的路线改回:'match“* page”=>“pages#show”'但真正的问题出现在我的控制器中。在rails 3.0.X中,你使用RAILS_ROOT,但是在3.1和以上,它是Rails.root。谢谢大家 – scommette 2012-02-22 20:10:54