Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:26:40+00:00 2026-06-03T07:26:40+00:00

What am I doing wrong with this helper for my HAML template? def display_event(event)

  • 0

What am I doing wrong with this helper for my HAML template?

  def display_event(event)
    event = MultiJson.decode(event)
    markup_class = get_markup_class(event)
    haml_tag :li, :class => markup_class do
      haml_tag :b, "Foo"
      haml_tag :i, "Bar"
    end
  end

This is the error:

haml_tag outputs directly to the Haml template.
Disregard its return value and use the - operator,
or use capture_haml to get the value as a String.

The template is calling display_event like this:

 - @events.each do |event|
     = display_event(event)

If I was using regular markup it would expand to the following

%li.fooclass
   %b Foo
   %i Bar
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:26:41+00:00Added an answer on June 3, 2026 at 7:26 am

    The clue’s in the error message:

    Disregard its return value and use the - operator,
    or use capture_haml to get the value as a String.
    

    From the docs for haml_tag:

    haml_tag outputs directly to the buffer; its return value should not be used. If you need to get the results as a string, use #capture_haml.

    To fix it, either change your Haml to:

    - @events.each do |event|
      - display_event(event)
    

    (i.e. use the - operator instead of =), or change the method to use capture_haml:

    def display_event()
      event = MultiJson.decode(event)
      markup_class = get_markup_class(event)
      capture_haml do
        haml_tag :li, :class => markup_class do
          haml_tag :b, "Foo"
          haml_tag :i, "Bar"
        end
      end
    end
    

    This will make the method return a string, which you can then display with = in your Haml.

    Note you need to make only one of these changes, if you make both they will cancel each other out and you’ll get nothing displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out what I'm doing wrong in this template. Here's my data:
What am I doing wrong with this: $sql = SELECT * FROM content WHERE
What am I doing wrong in this HTML code: <html> <head> </head> <body> <div
Can anyone please point out what im doing wrong with this Stored Procedure please.
Hi can someone tell me what i'm doing wrong in this jquery statement. I
What am I doing wrong to get this error? replacements = {} replacements[**] =
I'm mot sure if I'm doing this wrong or not I don't know if
I am completely new to iOS development so I may be doing this wrong
I hope this is something straightforward that I'm doing wrong. I saw something online
I know this probably really simple but Im not sure what im doing wrong...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.