给定如下的Rails路由约束:
class UserConstraint
def matches?(request)
User.where(code: request.path_parameters[:code]).any?
end
end
这将无法工作,因为有一个子路由。
routes.rb
constraints UserConstraint.new do
get ':code', to: 'documents#index', as: :documents
get ':code/*slug', to: 'documents#show', as: :document
end
它只返回以下内容:
ActiveRecord::RecordNotFound:
Couldn't find User with 'slug'={:code=>"show"}
这是不是只能用更多的约束才能解决?
https://stackoverflow.com/questions/53733412
复制相似问题