I have the same problem - I'm trying to use a convert a custom
FormBuilder to use haml.  Adding an

  include Haml::Helpers

in my class does change the open from Kernel#open to
Haml::Helpers#open call and was one of the first things I tried.  But
that turns out not to be the nut of the haml/FormBuilder integration
problem.  The problem seems to be that haml inserts state and methods
into ActionView::Base.  Specifically, haml's pushs a Haml::Bufer onto
@haml_stack member of the ActionView::Base instance and has, at least,
an is_haml? method.  Because my class extends FormBuilder, I don't
have access to either of these.

The solution I'm testing now: make the ActionView::Base instance
available to my class.  Implementation:

 1. add

   options[:action_view_base] = self if self.class == ActionView::Base

  in my custom form_for call, just prior to the form_fields call.

 2. In my extended FormBuilder class, add these methods:

    def initialize(object_name, object, template, options,
proc)
      @action_view_base =
options.delete(:action_view_base)
 
super
 
end

    # only fixes is_haml? since open and puts are defined in Ruby's
Kernel object and globally accessible
    def method_missing(method,
*args)
      @action_view_base.send(method,
*args)
 
end

    def puts(text =
"")
 
@action_view_base.puts(text)
 
end

    def open(name, attributes = {}, alt_atts = {},
&block)
      @action_view_base.open(name, attributes, alt_atts,
&block)
    end

This fixes the case where custom form for is called.  If your code
uses a custom FormBuilder in another way, a similar fix should work if
you can provide access to the ActionView::Base instance.

Comments, suggestions, alternatives to my code are welcome.

-Andy


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to