首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

rails 三 在route中重定向

2012-12-28 
rails 3 在route中重定向Yourapp::Application.routes.draw do#Last route in routes.rbmatch *a, :to

rails 3 在route中重定向

Yourapp::Application.routes.draw do  #Last route in routes.rb  match '*a', :to => 'errors#routing'endNOTE: The "a" is actually a parameter in the Rails 3 Route Globbing technique. For example, if your url was /this-url-does-not-exist, then params[:a] equals "/this-url-does-not-exist". So be as creative as you'd like handling that rogue route.app/controllers/errors_controller.rbHere, I handle my routing errors. I leverage previous 404 handling code from my original ApplicationController mentioned above. So, my errors_controller.rb looks like this:class ErrorsController < ApplicationController  def routing    render_404  endendHowever, feel free to modify to fit your individual needs. Everyone's situation will be slightly different. For example, if you're not going to reuse your 404 error handling logic, then here's the full ErrorsController without inheritance:class ErrorsController < ApplicationController  def routing   render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false  endend



match "/posts/github" => redirect("http://github.com/rails.atom")match '*path' => redirect('/')   unless Rails.env.development?match ':graphs/:id(/:method)' => 'pages#something'



同行链接

热点排行