Class: FieldErrorProcChanger

Inherits:
Object
  • Object
show all
Defined in:
lib/field_error_proc_changer.rb

Instance Method Summary collapse

Constructor Details

#initialize(proc) ⇒ FieldErrorProcChanger

Returns a new instance of FieldErrorProcChanger.



2
3
4
# File 'lib/field_error_proc_changer.rb', line 2

def initialize(proc)
  @new_proc = proc
end

Instance Method Details

#after(controller) ⇒ Object

This will run after the action if and only if before returned true.



16
17
18
# File 'lib/field_error_proc_changer.rb', line 16

def after(controller)
  ActionView::Base.field_error_proc = @old_proc
end

#before(controller) ⇒ Object

This will run before the action. Returning false aborts the action.



8
9
10
11
12
# File 'lib/field_error_proc_changer.rb', line 8

def before(controller)
  @old_proc = ActionView::Base.field_error_proc
  ActionView::Base.field_error_proc = @new_proc
  true
end