A
A
Anton Ivanov2016-10-29 13:10:48
Ruby on Rails
Anton Ivanov, 2016-10-29 13:10:48

Why don't multiple constraints in rails routing work?

Hello.
Here is routes.rb:

Rails.application.routes.draw do
  constraints Constraints::AppRouter.new('first_domain') do
   ...
    get '/' => 'users#search', constraints: -> (request) { request.params[:q].present? }
   ...
  end

  constraints Constraints::AppRouter.new('second_domain') do
    get '' => 'tech#default_action'
  end

If the request contains the "q" parameter, then control is transferred to users#search regardless of the domain. Constraints::AppRouter#matches? in this case is not even called.
Do I understand correctly that the general constraints, which are decorated with blocks, are eventually applied to each route. Then those constraints that were written in the routes themselves are applied.
Then I can explain this behavior.
That is, in order to do what I need, it is necessary to take into account the one at the top in each "inline" constraint?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question