簡體   English   中英

如何在路線中實施約束,根目錄使用rails 2.3.x

[英]How to implement constrains in routes , rails 2.3.x for root

我正在嘗試根據子域請求重新路由根路徑。 我瀏覽了幾篇在Rails 3的路線中提到“約束”的文章,如下所述

MyKillerApp::Application.routes.draw do |map|  
  resources :comments  
  resources :articles  
  resources :blogs
  constraints(Subdomain) do  
    match '/' => 'blogs#show'
  end
  root :to => "blogs#index"  
end

lib/subdomain.rb

class Subdomain  
  def self.matches?(request)  
    request.subdomain.present? && request.subdomain != 'www'  
  end  
end

可以在rails 2.3 ....中實現相同的功能嗎?

I came around the problem using the subdomain-fu gem. Thanks for the help.... :-)

不,路由器限制是Rails 3中的新功能。

在rails 2.3.x中沒有隱含此功能,在rails 3中是隱含的。您始終可以編寫自己的方法來進行映射,並將那些鏈接路由到該特定方法,然后從那里重新路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM