一个路由名称的两个资源

时间:2015-11-26 19:21:21

标签: ruby-on-rails routes

我正在学习rails并下载了一些rails项目(rails 3.2.6),它在routes.rb中有这样的条目:

 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">

    <xs:complexType name="action">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="actid" type="xs:string" use="required"/>
                <xs:attribute name="acttyp" type="acttype" use="required"/>
                <xs:assert
                    test="
                        if (@actid = '123') then
                            @acttyp = 'type1'
                        else
                            true()"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="acttype">
        <xs:restriction base="xs:string">
            <xs:enumeration value="type1"/>
            <xs:enumeration value="type2"/>
            <xs:enumeration value="type3"/>
            <xs:enumeration value="type4"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="e" type="action"/>
</xs:schema>

很简单,基于该用户登录或根路由导致不同的控制器。我对吗? 但是,如果我将项目中的rails版本更改为4.2.1,我会在服务器启动时收到错误:

require 'logged_in_constraint'

VkontakteOnRails::Application.routes.draw do
  get 'callback'  => 'sessions#callback'
  delete 'logout' => 'sessions#destroy'

  root to: 'main#index', constraints: LoggedInConstraint.new
  root to: 'sessions#new'
end

是否意味着新的导轨不再支持此功能了?

2 个答案:

答案 0 :(得分:1)

您可以将as:选项添加到第二个根路由:

VkontakteOnRails::Application.routes.draw do
  # some code here
  root to: 'main#index', constraints: LoggedInConstraint.new
  root to: 'sessions#new', as: :unauth
end

答案 1 :(得分:0)

每个应用程序只能使用一个root。如果它未包含在namespace

root to: "home#index"

namespace :admin do
  root to: "admin#index"
end