2011-02-15 24 views
3

它曾經是,你需要他們通過放置Typus路線順序

Typus::Routes.draw(map) 

在你的routes.rb文件中的相應點,你可以準確地加載Typus路線。看起來這不再被支持,並且它們總是在所有的應用程序路線之後加載。這會導致最後必須定義的Catchall路線問題。有誰知道現在如何控制typus的加載順序?有沒有辦法讓它們在任何應用程序路由之前定義,而不是之後?謝謝!

回答

3

我周圍有留下我的包羅萬象的路線在我的應用程序的routes.rb的結束,而是從Typus匹配的URL將其排除:

# A catch all route 
match '*path' => 'content#show', :constraints => lambda{|request| 
    !request.path.starts_with?("/admin") # excluded if typus will be taking it... 
} 

這可能或現在可以爲你工作...

+0

是的,這是一個合理的解決方案。只希望它可以像過去一樣乾淨地完成。 – njorden 2011-02-25 18:06:28

0

我正在尋找相同的答案。

目前我已經採取從typus的config/routes.rb複製內容並將其放置到我的routes.rb文件中,在catchall路由之前。

這是一個可怕的,駭人聽聞的解決方案,但它解決了我眼前的問題。

例子:

# TODO: KLUDGE: MANUALLY BRING THE TYPUS ROUTES IN 
    #  Typus used to provide : 
    #   Typus::Routes.draw(map) 
    #  But that is no longer the case. 
    scope "admin", :module => :admin, :as => "admin" do 

    match "/" => "dashboard#show", :as => "dashboard" 
    match "user_guide" => "base#user_guide" 

    if Typus.authentication == :session 
     resource :session, :only => [:new, :create, :destroy], :controller => :session 
     resources :account, :only => [:new, :create, :show, :forgot_password] do 
     collection do 
      get :forgot_password 
      post :send_password 
     end 
     end 
    end 

    Typus.models.map { |i| i.to_resource }.each do |resource| 
     match "#{resource}(/:action(/:id(.:format)))", :controller => resource 
    end 

    Typus.resources.map { |i| i.underscore }.each do |resource| 
     match "#{resource}(/:action(/:id(.:format)))", :controller => resource 
    end 
    end 
    # END KLUDGE 

    # Catch all to the state page handler 
    match '/:page' => 'pages#show', :as => 'page'