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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:47:35+00:00 2026-06-06T04:47:35+00:00

I have the following code in one of my Rails 3 application views: <ul>

  • 0

I have the following code in one of my Rails 3 application views:

<ul>
<li style="position:relative">
<b>MR</b> - 18 Jun. 2012 -  11:07<br />
<p style="width:85%">Paid by Cheque  000562</p>
<span style="position:absolute;top:0px;right:0px;text-align:right">&pound;0,00<br /><b>Balance: -&pound;7,36</b></span>
</li>
<hr />
<li style="position:relative">
<b>JJ</b> - 01 May. 2012 -  09:35<br />
<p style="width:85%">label 2 Packets Recovery -Rabbit</p>
<span style="position:absolute;top:0px;right:0px;text-align:right">&pound;0,00<br /><b>Balance: &pound;7,36</b></span>
</li>
<hr />

This displays the content as follows:

Screenshot

The raw Rails code is as follows:

<ul>
<% @animal.clinicals.each do |clinical| %>
<li>
<b><%= clinical.UserID %></b> - <%= clinical.FullDateTime.strftime("%d %b. %Y -  %H:%M") %><br />
<p><%= clinical.ClinicalText %></p>
<span><%= number_to_currency(clinical.Fees, :unit => "&pound;", :separator => ",", :delimiter => "") %><br /><b>Balance: <%= number_to_currency(clinical.LineBalance, :unit => "&pound;", :separator => ",", :delimiter => "") %></b></span>
</li>
<hr />
<% end %>
</ul>  

What I am trying to do is alter the HTML code depending on the values in the ClinicalText field. For example, the following are possible entries to that field:

label 2 Packets Recovery -Rabbit
Surcharge (Credit)
disp 250 Tabs...

So, if the ClinicalText contains ‘label’ at the beginning I would like to remove the word label and add a css style to the li. Likewise, if it contains ‘Surcharge’ or ‘disp’ I would like to add different css styles to the li.

I can think of a way of doing this using if, else and elseif statements in the view but I would prefer this to be in a helper of some kind.

Any pointers would be appreciated!

  • 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-06T04:47:37+00:00Added an answer on June 6, 2026 at 4:47 am

    I’d write a helper that generates the whole <p> tag – that’ll make it easier for you to add classes, which you can then style with CSS. You can use a case (switch in most other languages) statement:

    def format_clinical_text(txt)
        cls = ''
    
        case(txt)
        when /\Alabel/i
            txt.sub!(/label\s*/, '')
            cls = 'label'
        when /\Asurcharge/i
            cls = 'surcharge'
        when /\Adisp/i
            cls = 'disp'
        end
    
        return "<p class=\"#{cls}\">#{ERB::Util.h(txt)}</p>".html_safe
    end
    

    Then this line:

    <p><%= clinical.ClinicalText %></p>
    

    Would become:

    <%= format_clinical_text(clinical.ClinicalText) %>
    

    And that’s it! Note that those regexes are case insensitive, but require the trigger word to be the very first thing in the input string (no spaces or nuthin); also, only the "label" case strips out the word it matches. That’s how I interpreted your question, but I could be wrong. Tweak as necessary.

    Hope that helps!

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

Sidebar

Related Questions

Using linkedin-j , I have the following code in one part of my application
I have a Rails 3 application and I am using the following code to
I have the following code in one of my controllers (in a Rails 3.1
I have the following code in one of my Rails (3.1) controllers: @count =
I have the following code in one cpp file which is part of a
I have the following code in one of our projects webpages: XmlDocument xDoc =
I have the following code snippet: enum { one } x; enum { two
In Scala IDE I have the following code: package pkg.one object S { class
I have the following code and everytime I click on one of the markers,
I have the following code which swaps out one divs innerHTML for the others

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.