Ive created a good editor in jQuery, and I want to add it as a helper form method.
how can i make a new form help method?
ideal id like to be able to call:
f.nice_editor :field
The object assigned form_foris an instance ActionView::Helpers::FormBuilder. So all you have to do is add the instance methods there.
form_for
ActionView::Helpers::FormBuilder
class ActionView::Helpers::FormBuilder def custom_field(...) ... end end
: nice_editor? , ActionView:: Helpers:: FormBuilder . /. FormBuilder.
, , items_helper.rb:
module ItemsHelper # this is one way to define new instance methods ActionView::Helpers::FormBuilder.class_eval do def nice_editor(conf,*opts) ... end end end
. , , self.included() FormBuilder.
, :
class ActionView::Helpers::FormBuilder def nice_editor(conf) #stuff to draw the editor end end
"conf" , . f.