【问题标题】:How to implement constrains in routes , rails 2.3.x for root如何在路由中实现约束,rails 2.3.x for root
【发布时间】:2013-10-11 05:35:58
【问题描述】:

我正在尝试根据子域请求重新路由根路径。我浏览了几篇在 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 中也能实现同样的功能吗.....?

【问题讨论】:

  • 我不是 100% 确定,但我不这么认为

标签: ruby-on-rails ruby-on-rails-3 routes


【解决方案1】:
I came around the problem using the subdomain-fu gem. Thanks for the help.... :-)

【讨论】:

    【解决方案2】:

    不,路由器约束是 Rails 3 中的一项新功能。

    【讨论】:

      【解决方案3】:

      您在 rails 2.3.x 中并没有隐含的此功能,它在 rails 3 中具有。您始终可以编写自己的方法来进行映射并将这些链接路由到该特定方法并从那里重新路由。

      【讨论】:

        猜你喜欢
        • 2013-04-06
        • 1970-01-01
        • 2013-09-25
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 2017-08-18
        • 1970-01-01
        • 2014-04-25
        相关资源
        最近更新 更多