【问题标题】:Rails3 routing precedenceRails3 路由优先级
【发布时间】:2011-11-09 04:53:54
【问题描述】:

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

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

我正在使用ckeditor gem 来获得编辑器支持。我的rake routes如下:

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

如您所见,我的问题是:

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

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

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

提前致谢。

【问题讨论】:

    标签: ruby-on-rails-3 routing


    【解决方案1】:

    路由文件是按从上到下的顺序处理的,所以只需更改路由的顺序,以便您的包罗万象在 ckeditor 内容之后。

    【讨论】:

    • 嗨@Richard,感谢您的回答,但问题是“ckeditor”路线来自“ckeditor”gem 的路线。但是我所有的其他路由都在 config/routes.rb 中,
    【解决方案2】:

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

    喜欢这个

    namespace :ckeditor, :only => [:index, :create, :destroy] do
        resources :pictures
        resources :attachment_files
    end
    
    match '*url', :controller => 'site', :action => 'dynamic_page'
    

    现在可以正常使用了

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多