Solved with this method, don't know how efficient it is though:
def matches?(request)
@users.each do |user|
return true if request.path_parameters[:client_code] == user.client_code
end
end
Frage
I want to constrain my routes if a match is found in the params
like so:
constraints :client_code => User.all.client_code.any? do
get ":client_code" => "share#index", :as => :shares
get ":client_code/:id" => "share#show", :as => :share
end
What should go instead of User.all.client_code.any?
? I really cannot figure it out.
Thanks! UPDATE
I've made a constraints object like so:
class ClientCodeConstraint
def initialize
@users = User.all
end
def matches?(request)
@users.where(:client_code => request).first
end
end
And changed the constraints ...
line in routes.rb
to this:
constraints ClientCodeConstraint.new do ...
Am I on the right track? I'm getting this response:
undefined method `where' for #<Array:...
Lösung
Solved with this method, don't know how efficient it is though:
def matches?(request)
@users.each do |user|
return true if request.path_parameters[:client_code] == user.client_code
end
end