rails 3.1, how to add custom condition to after_filter?
-
26-10-2019 - |
Question
How can I add a custom condition for after_filter
or before_filter
How can I have something like this:
after_filter :handle_student_time_tracking, :condition=> ( !current_student.nil? )
I can put the condition inside handle_student_time_tracking but, I think there is a better way Please advice
Solution
You should put the conditions in your filter, not on the after_filter call. Like this:
after_filter :handle_student_time_tracking
def handle_student_time_tracking
raise "I'm in an after filter!" if current_student.present?
end
The conditions that filters provide are for actions, like only
and except
, not based on other conditions.
Reference:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow