2013-02-15 29 views
0

我有...Rails爲什麼要爲我的#collection#route尋找一個ID?

的routes.rb

resources :standards do 
    collection do 
     get :none 
    end 
    end 

我得到rake routes如下:

none_standards GET /standards/none(.:format)     standards#none 

我在standards_controller.rb如下:

def none 
end 

那麼,爲什麼我會在/ standards/none處出現「無法找到沒有ID的標準」錯誤?

隨着better_errors,它說:

(gem) activerecord-3.2.11/lib/active_record/relation/finder_methods.rb 
    305 
    306  ids = ids.flatten.compact.uniq 
    307 
    308  case ids.size 
    309  when 0 
    310   raise RecordNotFound, "Couldn't find #{@klass.name} without an ID" 
    311  when 1 
    312   result = find_one(ids.first) 
    313   expects_array ? [ result ] : result 
    314  else 
    315   find_some(ids) 

... 

Instance Variables 

@table 
#<Arel::Table:0x007fc321207650 @name="standards", @engine=Standard(id: integer, name: string, description: string, created_at: datetime, updated_at: datetime), @columns=nil, @aliases=[], @table_alias=nil, @primary_key=nil> 
@klass 
Standard(id: integer, name: string, description: string, created_at: datetime, updated_at: datetime) 

這是一個收集路線還不是會員的路線,所以這似乎很奇怪。

+0

你的'rake routes'輸出看起來與這條路線有關嗎? – 2013-02-15 04:36:14

+0

在我的文章中添加了詳細信息 – 2013-02-15 05:02:40

回答

1

的問題是與declarative_authorization。我必須在standards_controller.rb更改filter_resource_access(假定常規路線)至filter_access_to :all(涵蓋所有路線)。

0

對我來說,適用於以下設置怪!(只是檢查你的路由說的話)

#app/controllers/standards_controller.rb 
class StandardsController < ApplicationController 
    def none 

    end 
end 

#config/routes.rb 
resources :standards do 
    collection do 
    get :none 
    end 
end 

我的路線是

none_standards GET /standards/none(.:format)  standards#none 
    standards GET /standards(.:format)   standards#index 
       POST /standards(.:format)   standards#create 
    new_standard GET /standards/new(.:format)  standards#new 
edit_standard GET /standards/:id/edit(.:format) standards#edit 
     standard GET /standards/:id(.:format)  standards#show 
       PUT /standards/:id(.:format)  standards#update 
       DELETE /standards/:id(.:format)  standards#destroy 
      root  /
相關問題