Ruby function inside HAML code not able to produce HTML output

727 views
Skip to first unread message

Ashish Bhatia

unread,
Aug 19, 2010, 2:15:14 PM8/19/10
to Haml
Hi,

I have written a ruby function inside haml and calling it from there,
but if the function outputs merb form helpers(like select or
text_field)
the code gives an error "undefined local variable or method `_hamlout'
"
can someone please help

Note: I have to perform a ~100 LOC task twice therefore, instead of
copying the code , I am doing it using ruby functions in HAML code.

Nathan Weizenbaum

unread,
Aug 19, 2010, 2:38:26 PM8/19/10
to ha...@googlegroups.com
Can you give an example of the code that's causing this problem?


--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.


Ashish Bhatia

unread,
Aug 20, 2010, 2:21:50 PM8/20/10
to Haml
This code snippet http://pastebin.com/nuH20vBQ
produces following error http://pastebin.com/9WThiUHR

While http://pastebin.com/rkky0Mj8 does the same thing without
producing the error
So, essentially the problem is that any html output (using =) inside a
function call is creating a problem (not just merb helpers which were
mentioned in the original post)

On Aug 19, 11:38 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> Can you give an example of the code that's causing this problem?
>
> On Thu, Aug 19, 2010 at 11:15 AM, Ashish Bhatia
> <ashishbhatia...@gmail.com>wrote:
>
> > Hi,
>
> > I have written a ruby function inside haml and calling it from there,
> > but if the function outputs merb form helpers(like select or
> > text_field)
> > the code gives an error "undefined local variable or method `_hamlout'
> > "
> > can someone please help
>
> > Note: I have to perform a ~100 LOC task twice therefore, instead of
> > copying the code , I am doing it using ruby functions in HAML code.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Haml" group.
> > To post to this group, send email to ha...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > haml+uns...@googlegroups.com <haml%2Bunsu...@googlegroups.com>.

Nathan Weizenbaum

unread,
Aug 22, 2010, 5:20:22 PM8/22/10
to ha...@googlegroups.com
This is a consequence of the way Ruby and Haml work. The function doesn't have access to some of the local variables (namely _hamlout) that Haml needs to run. Thus putting Haml code in the function won't work.

To unsubscribe from this group, send email to haml+uns...@googlegroups.com.

Ashish Bhatia

unread,
Aug 23, 2010, 8:33:49 AM8/23/10
to Haml
OK thanks for that piece of info.
My basic problem is that I wish to generate two identical forms (with
differences in names,id of the fields)
And the haml code is 100 lines. So, rather than duplicating the code
is there some way to parameterize with/without using ruby functions.
Can you please suggest an alternate?

Regards,
Ashish

On Aug 23, 2:20 am, Nathan Weizenbaum <nex...@gmail.com> wrote:
> This is a consequence of the way Ruby and Haml work. The function doesn't
> have access to some of the local variables (namely _hamlout) that Haml needs
> to run. Thus putting Haml code in the function won't work.
>
> On Fri, Aug 20, 2010 at 11:21 AM, Ashish Bhatia
> <ashishbhatia...@gmail.com>wrote:
>
> > This code snippethttp://pastebin.com/nuH20vBQ
> > produces following errorhttp://pastebin.com/9WThiUHR
>
> > Whilehttp://pastebin.com/rkky0Mj8does the same thing without
> > producing the error
> > So, essentially the problem is that any html output (using =) inside a
> > function call is creating a problem (not just merb helpers which were
> > mentioned in the original post)
>
> > On Aug 19, 11:38 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> > > Can you give an example of the code that's causing this problem?
>
> > > On Thu, Aug 19, 2010 at 11:15 AM, Ashish Bhatia
> > > <ashishbhatia...@gmail.com>wrote:
>
> > > > Hi,
>
> > > > I have written a ruby function inside haml and calling it from there,
> > > > but if the function outputs merb form helpers(like select or
> > > > text_field)
> > > > the code gives an error "undefined local variable or method `_hamlout'
> > > > "
> > > > can someone please help
>
> > > > Note: I have to perform a ~100 LOC task twice therefore, instead of
> > > > copying the code , I am doing it using ruby functions in HAML code.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Haml" group.
> > > > To post to this group, send email to ha...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > haml+uns...@googlegroups.com<haml%2Bunsu...@googlegroups.com><
> > haml%2Bunsu...@googlegroups.com<haml%252Buns...@googlegroups.com>

Nathan Weizenbaum

unread,
Aug 23, 2010, 2:04:29 PM8/23/10
to ha...@googlegroups.com
Usually helpers or partials are used for avoiding code duplication.

To unsubscribe from this group, send email to haml+uns...@googlegroups.com.

Ashish Bhatia

unread,
Aug 24, 2010, 12:29:34 PM8/24/10
to Haml
Thanks.
My bad, I was not aware that it is possible to pass parameters to
partials.
It worked.


On Aug 23, 11:04 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> Usually helpers or partials are used for avoiding code duplication.
>
> On Mon, Aug 23, 2010 at 5:33 AM, Ashish Bhatia <ashishbhatia...@gmail.com>wrote:
>
> > OK thanks for that piece of info.
> > My basic problem is that I wish to generate two identical forms (with
> > differences in names,id of the fields)
> > And the haml code is 100 lines. So, rather than duplicating the code
> > is there some way to parameterize with/without using ruby functions.
> > Can you please suggest an alternate?
>
> > Regards,
> > Ashish
>
> > On Aug 23, 2:20 am, Nathan Weizenbaum <nex...@gmail.com> wrote:
> > > This is a consequence of the way Ruby and Haml work. The function doesn't
> > > have access to some of the local variables (namely _hamlout) that Haml
> > needs
> > > to run. Thus putting Haml code in the function won't work.
>
> > > On Fri, Aug 20, 2010 at 11:21 AM, Ashish Bhatia
> > > <ashishbhatia...@gmail.com>wrote:
>
> > > > This code snippethttp://pastebin.com/nuH20vBQ
> > > > produces following errorhttp://pastebin.com/9WThiUHR
>
> > > > Whilehttp://pastebin.com/rkky0Mj8doesthe same thing without
> > > > haml%2Bunsu...@googlegroups.com<haml%252Buns...@googlegroups.com>
> > <haml%252Buns...@googlegroups.com<haml%25252Bun...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages