Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to set config.require_tenant to false when the path is /admin, but it doesn't work. #299

Open
hatsu38 opened this issue Nov 22, 2022 · 3 comments

Comments

@hatsu38
Copy link

hatsu38 commented Nov 22, 2022

I am using ActsAsTenant.
Recently, I wanted to change require_tenant dynamically because I plan to create an admin page.
So I looked at the README and rewrote acts_as_tenant.rb using lambda.

cat config/initializers/acts_as_tenant.rb

ActsAsTenant.configure do |config|
  config.require_tenant = lambda do
    puts "*" * 30
    p $request
    p $request_env
    puts "*" * 30
    if $request_env.present?
      return false if $request_env["REQUEST_PATH"].start_with?("/admin/")
    end
    true
  end
end

But $request_env is always nil even though the controller is working, so $request_env.present? is still false

******************************
nil
nil
******************************

Is there any way to set require_tenant to false only for the /admin path?

@drale2k
Copy link

drale2k commented Jan 2, 2023

Same issue here - $request_env always nil. Did you figure this out?

@excid3
Copy link
Collaborator

excid3 commented Jan 3, 2023

I believe this is just an example where you'd have to set a variable to access the request. @cmer made that PR to the Gemfile and can probably give some tips on that. #286

For example, you might want to use CurrentAttributes and set Current.request in a before_action so you can access it inside the lambda.

We may need to update the readme to show a complete example like that.

@hatsu38
Copy link
Author

hatsu38 commented Jan 7, 2023

Thank you for telling me. I misunderstood that I could use a variable called $request_env, but now I understand that I need to set the variable.

As you said, I'm glad the readme has a better example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants