-
Has anyone gotten something like this to work? Such that the routes end up as:
If so, how? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
If I set:
In Rails console:
So perhaps I can override url helpers somewhere to sub out the |
Beta Was this translation helpful? Give feedback.
-
The You would dynamically evaluate the class RodauthMain < Rodauth::Rails::Auth
configure do
prefix { "/api/auth/#{tenant_id}" }
# ...
end
def tenant_id
request.env[:tenant_id]
end
end You can then set the But I'd be interested to know how your Rails app is setting tenant ID. I would like to see if there was a more Railsy way of handling that in Rodauth. An alternative I see is adding a custom attribute accessor to the Rodauth object, and just setting the tenant ID there. For example, based on your comment: class RodauthMain < Rodauth::Rails::Auth
configure do
prefix { "/api/auth/#{tenant.path_key}" }
# ...
end
attr_accessor :tenant
end class RodauthApp < Rodauth::Rails::App
configure RodauthMain
route do |r|
r.on "api/auth", String do |path_key|
tenant = Tenant.fetch_by_path_key(path_key)
next unless tenant # consider route unmatched
rodauth.tenant = tenant
r.rodauth
end
end
end You could then set the same in the mailer: class RodauthMailer < ApplicationMailer
# ...
def rodauth(account_id, tenant_id)
instance = RodauthApp.rodauth(name).allocate
instance.tenant = Tenant.find(tenant_id)
instance.instance_eval { @account = account_ds(account_id).first! }
instance.instance_eval(&block) if block
instance
end
end |
Beta Was this translation helpful? Give feedback.
💥 Boom! Got it working, added examples to test suite here.