1

I need to create a few dynamic routes in my rails router in the following way:

Rails.application.routes.draw do
    account = Account.find_by(
      subdomain: request.subdomain,
      domain: request.domain
    )
    EditableField.where(account_id: account.id).links.each do |link|
      get link.link_href, to: link.method
    end
end

As shown above, I need to determine the account based on the request domain and subdomain, however I cant find how to access the request object in the rails router. What is the correct way to do this ?

1 Answer 1

0

I would suggest using the rack-rewrite gem https://github.com/jtrupiano/rack-rewrite

It is in lower level and give you much more options to do this kind of dynamic routing

And if you still want to do that in the routes.rb file, you can follow this answer https://stackoverflow.com/a/24411835/2529330

Enjoy :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.