0

我有...

路线.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)

这是一个收集路线而不是成员路线,所以这看起来很奇怪。

4

2 回答 2

1

问题出在declarative_authorization. 我不得不filter_resource_access在.filter_access_to :allstandards_controller.rb

于 2013-02-15T05:18:37.663 回答
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        / 
于 2013-02-15T04:40:04.393 回答