I have an Events controller on which I want to skip authentication if the event is open.
In my ApplicationController , I have this call to develop authenticate_user!
class ApplicationController < ActionController::Base before_action :authenticate_user! end
now, inside the "My Events" table, I have a logical field called public . I use this to check if an event is open or not. Like it in EventsController
class EventsController < ApplicationController skip_before_action :authenticate_user!, only: :show, if: Proc.new { :is_public? } end
But for some reason this did not work. so I had to do this:
class EventsController < ApplicationController skip_before_action :authenticate_user!, only: :show before_action :authenticate_user!, unless: :is_public? def is_public? @event.present? && @event.is_public end end
This works as expected and will skip authentication if @event.public = true , because the above repeats before_filter with the opposite condition after skipping.
I am wondering:
- what did i do right?
- This affects performance. if so, is there a better way?
source share