在Rails route.rb中正确的资源顺序 [英] Correct order of resources in Rails routes.rb

查看:94
本文介绍了在Rails route.rb中正确的资源顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于route.rb文件的组织方式,我不断收到奇怪的错误。最新的一个是某些函数无法在模型Relations控制器中找到动作显示(动作显然在那里)。我猜这是因为我正在通过集合添加一些自定义操作,并且弄乱了声明路由的顺序。.有人可以看看这个并说出什么问题吗?

I keep getting strange errors because of the way my routes.rb file is organized. The latest one is that some function cannot find action "show" in model Relations controller (the action is obviously there). 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


推荐答案

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

You might have an issue with resource :relations. Rule of thumb is: if you use the plural resources, then the name of the resource must also be plural (i.e. :relations), if you use resource, in singular, than you should use singular for the resource name too (i.e. :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. Compare that to the log of the failed request and see if every parameter matches up.

这篇关于在Rails route.rb中正确的资源顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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