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

  • SEARCH
  • Home
  • 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 4087208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:49:34+00:00 2026-05-20T18:49:34+00:00

I have a controller which does the following line before rendering the view and

  • 0

I have a controller which does the following line before rendering the view and outputting an error.

flash[:error]="Flash error"
flash[:info] = "Flash info"

I would like to format this nicely. For that I wrote a helper which looks like this

def show_flash
    a=""
    [:success, :info, :error, :warning].each do |key|
        a += content_tag(:div, flash[key], :id => key, :class => "#{key}") unless flash[key].blank?
    end
end

In my view, I call:

<%= show_flash %>

When I try to run this, the web page renders the full text of show_flash, including the div tags, angle brackets and all. When I inspect the element (using Firefox or Chrome), it shows the text surrounded with double quotes.

Then I tried changing one line in the helper as follows:

a = content_tag(:div, flash[key], :id=>key, :class=>"#{key]") unless flash[key].blank?

i.e. I would only capture the last content tag (error) instead of both of them.

In the second case, the web browser rendered the div tag formatted properly with my CSS rules for the “error” class. I didn’t see any div tags printed out in the browser.

Why did concatenating two content_tag elements cause me this grief?

I appreciate any help you can give me.

  • 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-05-20T18:49:35+00:00Added an answer on May 20, 2026 at 6:49 pm

    It turns out that when going from Rails 2 to Rails 3, html escaping is enabled by default, and you must explicitly disable it before concatenating content_tag strings. The code looks like:

    def show_flash
      a=content_tag(:span, "",:escape=>false)
      [:success, :info, :error, :warning].each do |key|
        a = a+content_tag(:div, flash[key], :id => key, :class => "#{key}", :escape=>false) unless flash[key].blank?
      end     
      a
    end
    

    That option, :escape=>false is what it took to make it work.

    Andrew Marshall pointed me in the right direction, and after some searching, I stumbled on the words of wisdom from Yehuda. That’s where the :escape clause became obvious.

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

Sidebar

Related Questions

I have a controller action which I would like to call another controller action.
I'm struggling here with a problem: I have a controller questions which has action
Say you have several webparts, one as a controller and several which take information
When submitting one form from view, how can i also read or have controller
I have two controllers which share most of their code (but must be, nonetheless,
I have a project which is source controlled using Subversion and VisualSVN. Since the
I have a controller with an action method as follows: public class InventoryController :
I have a controller action that is being executed by a link that was
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
Say I have a controller with an Index Method and a Update Method. After

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.