I have the following wildcard routes & constraints setup ...
get '*path' => 'profiles#show', constraints: SlugConstraint.new
get '*path' => 'blogs#show', constraints: SlugConstraint.new
and
class SlugConstraint
def initialize
@slugs = Slug.all.map(&:name)
end
def matches?(request)
request.url =~ /\/(.+)/
@slugs.include?($1)
end
end
... a variation based on the issue I described here: Rails wildcard route with database lookup & multiple controllers
My issue now is that if the first call to SlugConstraint.new returns false (so that the 2nd routes.rb SlugConstraint.new now gets called) I don't want to have to redo the call to:
Slug.all.map(&:name)
How do I properly save (or scope) the @slugs data from the first constraint call that failed, so that I can access it if needed in the next constraint call?
Thanks.