Add form help method

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
+5
source share
3 answers

The object assigned form_foris an instance ActionView::Helpers::FormBuilder. So all you have to do is add the instance methods there.

class ActionView::Helpers::FormBuilder
  def custom_field(...)
    ...
  end
end
+6
source

: 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.

+9

, :

class ActionView::Helpers::FormBuilder
    def nice_editor(conf)
         #stuff to draw the editor
    end
end

"conf" , . f.

+1

All Articles