bradpotts
bradpotts

Reputation: 329

if devise gem exists put before_action :authenticate_user! otherwise leave out

I have a rails engine I'd like to make more universal. I have before_action :authenticate_user! in my controllers for devise.

Is there a way I can put if devise gem exists put before_action :authenticate_user! otherwise leave out.

Upvotes: 1

Views: 121

Answers (1)

Kevin Sylvestre
Kevin Sylvestre

Reputation: 38092

Use defined? to look for Devise:

before_filter :authenticate_user!, if: -> { defined?(Devise) }

Upvotes: 2

Related Questions