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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:08:46+00:00 2026-06-03T22:08:46+00:00

I am using Nokogiri in a Rails 3 app. It ignores <br/> tags. I’d

  • 0

I am using Nokogiri in a Rails 3 app. It ignores

<br/> 

tags. I’d like to replace such tags with “, ” because they represent line breaks in addresses. How do I do this? I’ve tried the following, which doesn’t seem to help:

  doc.inner_html.gsub!("<br/>", ", ")
  • 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-03T22:08:48+00:00Added an answer on June 3, 2026 at 10:08 pm

    Simply:

    doc.css('br').each{ |br| br.replace ", " }
    

    Seen in action:

    require 'nokogiri'
    doc = Nokogiri.HTML('<address>900 Magnolia Road<br/>Nederland, CO<br/>80466</address>')
    puts doc.root
    #=> <html><body><address>900 Magnolia Road<br>Nederland, CO<br>80466</address></body></html>
    
    doc.css('br').each{ |br| br.replace ", " }
    puts doc.root
    #=> <html><body><address>900 Magnolia Road, Nederland, CO, 80466</address></body></html>
    

    If you want to be more careful and only replace the <br> inside an <address> tag (for example), then:

    doc.css('address > br').each{ |br| br.replace ", " }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that is parsing HTML using the nokogiri gem version
I'm using nokogiri with an xml document that looks something like this: <songs> <song>
I am trying to attach files in my RoR app. I am using Rails
I am using nokogiri to generate svg pictures. I would like to add the
Using Nokogiri and Ruby. I have a page to parse with div id's like:
I'm using Nokogiri::XML to parse responses from Amazon SimpleDB. The response is something like:
If I want to parse a HTML block using Nokogiri in Ruby like this:
I am using ROXML with Nokogiri for XML/Ruby Object Mapping in Rails 3 and
I'm using rails and the Nokogiri parser. My xml is as below and I'm
I need to parse HTML using Rails and Nokogiri. Here is the HTML: <body>

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.