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 9083615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:48:58+00:00 2026-06-16T20:48:58+00:00

html_safe and still escaped html I have the following reply helper: def mb_reply_login post

  • 0

html_safe and still escaped html

I have the following reply helper:

def mb_reply_login post
  if current_user
    "<button data-depth='" + post.depth.to_s + "' data-post-id='" + post.id.to_s + "'  class='mb_btn mb_reply btn'>reply</button>".html_safe
  else
    ...
  end

and call it from within views like so:

<%=mb_reply_login post %>

However, it’s return escaped html and am confused as to why? It seems like it shouldn’t according to Don't escape html in ruby on rails and the rails api.

How would I return unenscaped html? I tried

"<button data-depth='" + post.depth.to_s.html_safe + "' data-post-id='" + post.id.to_s.html_safe + "'  class='mb_btn mb_reply btn'>reply</button>".html_safe

but no dice

thx in advance

  • 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-16T20:48:59+00:00Added an answer on June 16, 2026 at 8:48 pm

    When you concatenate strings in Ruby on Rails, every single String that hasn’t been marked as html_safe is first escaped before concatentating.

    Using your second snippet, make sure to call .html_safe on every string (including the constants such as:

    "<button data-depth='"
    

    Better yet, you can use interpolation, such as:

    "<button data-depth='#{post.depth.to_s.html_safe}' 
     data-post-id='#{post.id.to_s.html_safe}' 
     class='mb_btn mb_reply btn'>reply</button>".html_safe
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a Rails 3.2.1 helper that keeps escaping HTML
I have a .js.erb file that has the following line $(#<%= user#{current_user.id}_following %>).html(<%= escape_javascript(link_to(pluralize(@count,'tag'),
I have an object in my controller @data=<meta property=\og:url\ content=\<%=SITE_URL%><%=request.request_uri%>\ />.html_safe When I print
I have an application that needs to display foreign HTML data (e.g. HTML-encoded email
I have this code: = link_to unsubscribe instantly, *|UNSUB|*.html_safe That generates this HTML: <a
if in html table have 5 row, 1 and 2 are safe, 3,4,5 must
With reference to the following link: http://docs.python.org/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe I wanted to know if the following:
I have a form where an user can post a global notice into the
I'm reading http://gcc.gnu.org/onlinedocs/libstdc++/manual/shared_ptr.html and some thread safety issues are still not clear for me:
I have a little php framework for HTML development. I basically made HTML semi-functional

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.