Answer the question
In order to leave comments, you need to log in
Why doesn't "not" work in constraints in rails routing?
Hello!
Here is the route.rb part:
Rails.application.routes.draw do
authorized = ->(request) { request.session[:user_id].present? }
constraints !authorized do
...
end
constraints authorized do
...
end
end
not_authorized = ->(request) { request.session[:user_id].blank? }
and "get involved" on it, then everything works. Answer the question
In order to leave comments, you need to log in
Your `authorized` is a lambda. That is, this is a function that will be executed every time the request comes to rails.
And this `!authorized`, this is the negation of the lambda, it will always be false. This is not a negation of the result of executing the lambda, it is a negation of the lambda object itself.
2.3.1 :001 > ->() { false }
=> #<Proc:[email protected](irb):1 (lambda)>
2.3.1 :002 > !(->() { false })
=> false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question