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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:55:58+00:00 2026-06-02T01:55:58+00:00

How can I replace dashes with a spaces & underscores with a commas at

  • 0

How can I replace dashes with a spaces & underscores with a commas at the same time?

I was able to replace underscores with commas, but when I tried to reiterate through the array again it gave some funky results.

Controller

  def activity_by_all_city
      @cities = ['Abilene_Texas','Akron_Ohio','Albuquerque_New-Mexico','Baton-Rouge_Louisiana']
  end 

View

<% @cities.each do |city|%>
    <%= link_to city.gsub!(/_/, ', '), 'activities-'+city.parameterize %><br>
<% end %>
  • 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-02T01:55:59+00:00Added an answer on June 2, 2026 at 1:55 am

    Try:

    <%= link_to city.replace(city.gsub(/-/, ' ').gsub(/_/, ', ')), 'activities-'+city.parameterize %><br>
    

    Gives:

    <a href="activities-albuquerque-new-mexico">Albuquerque, New Mexico</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can replace values as array by replace in javascript. I want done replace
Is there a way i can replace the values of one array with the
I am able to Mole WebRequest.CreateUri so that I can replace the hostname of
I can replace ABC(10,5) with (10)%(5) using: replaceAll(ABC\\(([^,]*)\\,([^,]*)\\), ($1)%($2)) but I'm unable to figure
Using Gmaps.map.replaceMarkers() I can replace entire marker set. But in my application I will
How can replace arabic number with latin number as that doesn't change number into
so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim
How i can replace some characters when user type a sentence in EditText? For
I need to know how I can replace the last s from a string
I was wondering if there is any way that I can replace substrings within

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.