Answer the question
In order to leave comments, you need to log in
Why is rails recommending a separate class for multidomain rather than a lambda?
Hello.
When looking for solutions for a single application to process requests on multiple domains, I find articles like this: stackoverflow.com/questions/4207657/rails-routing-...
This and all other articles recommend using a class to determine which of domains this block of routes is intended.
The following construction normally lives (and works) in my routing:
users_site = ->(request) { 'users.site' == request.host }
api_site = ->(request) { 'api.site' == request.host }
docs_site = ->(request) { 'docs.site' == request.host }
constraints users_site do
...
end
constraints api_site do
...
end
constraints docs_site do
...
end
Answer the question
In order to leave comments, you need to log in
No difference. The class is taken out if there is too much logic in the condition. You have only one line, so a lambda is enough. It's just a matter of code readability.
But I would never take it to a class at all, since every time I have to look for this class, climb into it and understand it. It's better to have everything in one place.
Well, this answer on SO is morally outdated: now putting something in lib is very bad. But then I don’t know where to store these classes - usually this is decided within the framework of a specific project, everyone does what is convenient for him.
In addition, an article on how to split routes.rb into multiple modules: blog.arkency.com/2015/02/how-to-split-routes-dot-r...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question