Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.dev

Handling requests with Rack and Rails

Rack Middleware for Ruby on Rails

The Clerk Ruby SDK comes with Rack middleware to lazily load the Clerk session and user. If added as a gem to Rails application, the Clerk::Authenticatable concern can be added to your controller.

This gives your controller and views access to the following methods:

  • clerk_session
  • clerk_user
  • clerk_user_signed_in?

If you want to protect a subset of your controllers (for example, if you have an admin section), you can add a before_filter like this:

Don't forget to set the environment variable CLERK_SIGN_IN_URL or the method clerk_sign_in_url will fail.

Was this helpful?

Clerk © 2022