Rails3路由优先级 [英] Rails3 routing precedence

查看:81
本文介绍了Rails3路由优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3创建一个简单的CMS。在我的 routes.rb 文件中,我具有以下条目可以捕获所有路由:

I'm creating a simple CMS with Rails 3. In my routes.rb file I have the following entry to catch all routes:

match '*url', :controller => 'site', :action => 'dynamic_page'

我正在使用 ckeditor gem用于编辑器支持。我的耙路如下:

I'm using ckeditor gem for editor support. My rake routes is as follows:

                     root        /(.:format)                              {:action=>"index", :controller=>"site"}
                                 /*url(.:format)                          {:action=>"dynamic_page", :controller=>"site"}
        ckeditor_pictures GET    /ckeditor/pictures(.:format)             {:action=>"index", :controller=>"ckeditor/pictures"}
        ckeditor_pictures POST   /ckeditor/pictures(.:format)             {:action=>"create", :controller=>"ckeditor/pictures"}
         ckeditor_picture DELETE /ckeditor/pictures/:id(.:format)         {:action=>"destroy", :controller=>"ckeditor/pictures"}
ckeditor_attachment_files GET    /ckeditor/attachment_files(.:format)     {:action=>"index", :controller=>"ckeditor/attachment_files"}
ckeditor_attachment_files POST   /ckeditor/attachment_files(.:format)     {:action=>"create", :controller=>"ckeditor/attachment_files"}
 ckeditor_attachment_file DELETE /ckeditor/attachment_files/:id(.:format) {:action=>"destroy", :controller=>"ckeditor/attachment_files"}

我的问题是,如您所见:

My problem is, as you can see:

/*url(.:format)     {:action=>"dynamic_page", :controller=>"site"}

..在ckeditor路由之前加载,因此ckeditor路由不起作用。有人可以在加载ckeditor路由之前帮助我吗:

..loads before the ckeditor routes and hence ckeditor routes are not working. Can someone help me out on loading ckeditor routes before:

/*url(.:format)     {:action=>"dynamic_page", :controller=>"site"}

谢谢。

推荐答案

我想到的解决方案是将ckeditor路由添加到 routes.rb 文件中手动

The solution I came up with is adding the ckeditor routes to the routes.rb file manually

像这样

namespace :ckeditor, :only => [:index, :create, :destroy] do
    resources :pictures
    resources :attachment_files
end

match '*url', :controller => 'site', :action => 'dynamic_page'

现在可以正常使用了

这篇关于Rails3路由优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆