Rails3 routing precedence

我的未来我决定 提交于 2019-12-23 05:19:49

问题


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'

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"}

..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"}

Thanks in advance.


回答1:


The routes files is processed in order from top to bottom, so just change the order of the routes so that your catch-all is after the ckeditor stuff.




回答2:


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

like this

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

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

Now its working fine



来源:https://stackoverflow.com/questions/8060488/rails3-routing-precedence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!