我基本上是想在我的routes.rb中创建一个自定义索引:
resources :tokens do
resources :visits
collection do
get :open
get :expired
end
end我的路由显示为:
open_tokens GET /tokens/open(.:format) tokens#open
expired_tokens GET /tokens/expired(.:format) tokens#expired我在令牌控制器中定义了open和expired
def open
@q = Token.open_token.includes(:households, :visits).search(params[:q])
@tokens = @q.result
respond_to do |format|
format.html {render template: 'tokens/open'}
end
end
def expired
@q = Token.expired_token.includes(:households, :visits).search(params[:q])
@tokens = @q.result
respond_to do |format|
format.html {render template: 'tokens/expired'}
end
end但它转到我的show控制器,并显示以下错误:
Couldn't find Token with id=open它在我的Show动作中崩溃了:
Better Errors将请求显示为:
{"action"=>"show","controller"=>"tokens","id"=>"open"}
在我看来,动作应该是没有参数的开放的。
我做错了什么?
发布于 2018-07-26 10:24:31
我想我可能已经回答了我的问题,因为似乎Rails的每个控制器只能有一个索引,所以我不能定义另一个作为索引的视图。
所以现在我想要做的是传递一个参数,这样我就可以应用一个开放的作用域或者一个过期的作用域
https://stackoverflow.com/questions/51528252
复制相似问题