monkeypatching - Custom Form Elements in Rails -


after "text" itemprop = "text">

Then I'm new to the rail and I'm trying to figure out what is the customized method of adding custom form elements Am Currently the way I am doing it is super grotty.

ActionView module helpers module FormOptionsHelper def some_new_field (object, method, option = {}, html_options = {}) #code code end-end class FormBuilder def contract_year_select (method, option = {}, Html_options = {}) @ template.some_new_field (@object_name, method, objectify_options (option), @ default_options.merge (html_options) end end end

I have seen it though

  class form :: application form builder & lt; ActionView :: Helpers :: Form Builder Form :: ApplicationHelper.instance_methods.each do | Selector | Src = & lt; & Lt; -end_src def # {selector} (method, option = {}) @ template.send (# {selector.inspect}, @object_name, method, objectify_options (option)) end end_src class_eval src, __FILE__, __LINE__ end personal def objectify_options ( Option): @ default_options.merge (options.merge (: object = & gt; @object)) end of end  

(to)

extension formulber punching of this duck Sounds like a better solution than Is there any other way to do this that does not need to copy some of the formula square directly into my custom?

Two parter here:

First of all, For new, I would recommend using the Formtastic gem. M.V.C is abused and neglected in V rail.

The formtest has been tested very well and support for Rail 3

With formstock you can increase custom elements to its magnificent class And can get the full host. Other benefits beyond ordinary field display

Second, being extended to the square is definitely acceptable. I like the module method because it is easy to see.

  module form :: applicationformbilder class whateverYourExtending def some_special_method (stuff) # All types The end of the special content of  

But I hardly know what I'm talking about here ... this is right on the edge of my understanding.

Just talked about the form and I like the formattic!


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -