简体   繁体   English

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

[英]Correct order of resources in Rails routes.rb

I keep getting strange errors because of the way my routes.rb file is organized. 由于route.rb文件的组织方式,我不断收到奇怪的错误。 The latest one is that some function cannot find action "show" in model Relations controller (the action is obviously there). 最新的一个是某些函数无法在模型Relations控制器中找到动作“显示”(动作显然在那里)。 I guess this is because I am adding some custom actions via collection and something about the order in which the routes are declared is messed up.. Can somebody please have a look at this and say what is wrong? 我猜这是因为我通过集合添加了一些自定义操作,并且弄清楚了声明路由的顺序。.有人可以看看这个并说错吗?

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

You might have an issue with resource :relations . 您可能遇到resource :relations Rule of thumb is: if you use the plural resources , then the name of the resource must also be plural (ie :relations ), if you use resource , in singular, than you should use singular for the resource name too (ie :relation ). 经验法则是:如果您使用复数resources ,那么resources名称也必须是复数(即:relations ),如果您使用resource ,也应使用单数形式,而不是也应使用单数形式表示资源名称(即:relation )。

Other possible problems: your indentation is off. 其他可能的问题:缩进不正确。 Maybe it's just a copy-paste issue, but check it nonetheless, because you might have some unexpected nesting going on. 也许这只是一个复制粘贴问题,但还是要进行检查,因为可能会发生一些意外的嵌套。

Also inspect rake routes CONTROLLER=relations . 还要检查rake routes CONTROLLER=relations Compare that to the log of the failed request and see if every parameter matches up. 将其与失败请求的日志进行比较,看看是否每个参数都匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM