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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:29:01+00:00 2026-05-27T07:29:01+00:00

I have the user submit a single line (description) that must have one number

  • 0

I have the user submit a single line (“description”) that must have one number in it.

Currently I have the user submit the number at the beginning of the description “253 foo foo bar bar” — but I want to change it so that the number can be anywhere.
“foo foo foo 253 bar bar bar”, “253 foo foo bar bar”, “bar bar foo 253”

The number has a different CSS class. My goal is display the description string and wrap tags around the number. How should I structure my models / views, using Javascript / rails, in order to do this?

Here are possibilities I’ve thought of. I want to preserve MVC and also maximize performance in rendering views. The user is submitting one line that gets processed in the back end. At the moment, my database has Item.description and Item.number

  1. Item.description_before, Item.number, Item.description_after — When the user submits, split the description string into two parts. This seems like it’ll have good performance and readability because in the view, I can just do <%= Item.description_before + "#{Item.number}" + Item.description_after. But then it also seems strange splitting the description into two parts.

  2. Item.number_position – Record the position of the number in the string and then use ruby string manipulation to add <class> tags around the nth character in the string.

  3. Use Javascript to find the number – But then if I’m listing 25 posts, I’d have to call this function 25 times each time the page loads and do string manipulation that way, which seems problematic.

But I’m definitely looking for new suggestions because I’m not an expert at this by any means! Or if you would have done one of the above options, any answers would be helpful as well. Thanks!

  • 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-27T07:29:02+00:00Added an answer on May 27, 2026 at 7:29 am

    A view helper which does a regex substition would be fine and fast enough. Something like:

    string.gsub(/[0-9]+/, '<span style="color:red">$1</span>')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a wysiwyg iframe where the user can submit input to another
I have a submit button that changes when the user hovers his mouse over
The problem I have is that I have multiple submit inputs in a single
I have a form, when user submit the form, I want to direct the
I have an HTML page with a simple form. When the user clicks submit,
I have a form, and a submit handler in jQuery. When the user submits
I have an ASP.NET MVC application, when a user clicks on the submit button
I want to have a single button that when clicked opens a file dialogue,
I have a highly dynamic single page interface where various user events trigger new
I have a jquery Ajax call function that I use to submit form to

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.