我有...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)
這是一個收集路線還不是會員的路線,所以這似乎很奇怪。
你的'rake routes'輸出看起來與這條路線有關嗎? – 2013-02-15 04:36:14
在我的文章中添加了詳細信息 – 2013-02-15 05:02:40