在Rails routes.rb中正确的资源顺序

时间:2012-06-11 17:36:07

标签: ruby-on-rails routes

由于我的routes.rb文件的组织方式,我一直收到奇怪的错误。最新的一个是某些功能无法在模型关系控制器中找到动作“显示”(动作显然存在)。我想这是因为我通过收集添加了一些自定义操作,并且关于声明路由的顺序有些混乱。有人可以看看这个并说出错了吗?

YApp::Application.routes.draw do

  require 'resque/server'

  match 'login' => 'user_sessions#new', :as => :login
  match 'logout' => 'user_sessions#destroy', :as => :logout
  match '/get_idx',  :to => 'nodes#get_idx'


  resource :relations do
    collection do
      post 'this_relation'
      post "iframize"
    end
  end


  resource :words do
  get 'page/:page', :action => :index, :on => :collection
    collection do
      get 'front'
      get 'index'
    end
  end

    resource :recommendations do
      collection do
        get 'find_votes'
      end
    end


  get "connotation/create"

  get "connotation/edit"

  get "connotation/update"

  root :to => "words#front", :as => :homepage

  resources :users, :user_sessions, :relations,  :evaluation, :phrases, :metawords, :nodes, :recommendations, :words


  mount Resque::Server.new, :at => "/resque"
  match 'about' => 'words#index' , :as => :about
  match 'contact' => 'keywords#index' , :as => :contact


end

1 个答案:

答案 0 :(得分:0)

resource :relations可能存在问题。经验法则是:如果您使用复数resources,那么资源的名称也必须是复数(即:relations),如果您以单数形式使用resource,那么您应该使用也可以使用单数作为资源名称(即:relation)。

其他可能的问题:您的缩进已关闭。也许它只是一个复制粘贴问题,但是请检查它,因为你可能会有一些意想不到的嵌套。

同时检查rake routes CONTROLLER=relations。将其与失败请求的日志进行比较,看看每个参数是否匹配。