Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use Rails::CurrentAttributes with current_user
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :set_current_user
private def set_current_user
Current.user = current_user
end
end
module ApplicationHelper
def current_user
Current.user || super
end
end
# app/models/current.rb
class Current < ActiveSupport::CurrentAttributes
attribute :user
end
@existentialmutt
Copy link
Author

note that when rendering outside a controller you'll have to manually set Current.user in your job/channel/etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment