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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:57:10+00:00 2026-05-29T22:57:10+00:00

I was writing the helper for my rails app, which should make some manupulations

  • 0

I was writing the helper for my rails app, which should make some manupulations with string, and when I found this. If I use gsub method exactly after escaping, then this code doesn’t work like I wanted to (it doesn’t find the number 999).

require 'active_support/core_ext/string'

text = ">999"

text = ERB::Util.html_escape(text)

# text = text.downcase
text.gsub!(/\&gt\;(\d+)/) { "found [#{$1}]" }

puts text

In another case, if I uncomment text = text.downcase, i.e. apply any method to string, then all works fine. So what should I do if I would like to use gsub exactly after html_escape method?

  • 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-29T22:57:11+00:00Added an answer on May 29, 2026 at 10:57 pm

    You are hitting an awesome feature; try this:

    # ...as before.
    text = ERB::Util.html_escape(text)
    puts text.class
    

    text is actually an instance of ActiveSupport::SafeBuffer, which presumably implements the gsub! method, takes a block, but gets it somehow wrong – in that it doesn’t result in $1 being set.

    You can work around this by way of either:

    text = text.to_s.gsub!(...)
    text = text.gsub!(...) {|match| "found [#{match}]" }
    

    You might find this inconsistency fixed in a later version of the ActiveSupport code, but otherwise you might as well file the bug report now; that gsub! behaviour is well documented and should be preserved.

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

Sidebar

Related Questions

I am writing a Rails helper method that will add wrapper html to captured
When writing a helper method for a class in C++, should it be declared
I'm trying to use a helper in my rails view to draw some haml
I am writing a test helper and it has this method: def todo msg
Im writing some helper functions for a project im working on. I've always wanted
I am writting my custom helper. I tried to use the language helper: $this->lang->line('site_title')
I'm writing some unit tests for one of my rails models. It's a large
I am writing a helper for my application which writes out a menu item
I'm somewhat of a Rails newbie. I'm writing a couchrest-rails app, so am not
I'm writing a helper method for ASP.NET MVC and I need to call Url.Content

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.