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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:10:13+00:00 2026-05-22T15:10:13+00:00

New-ish to Rails… I’ve created a helper to format race names & their dates.

  • 0

New-ish to Rails… I’ve created a helper to format race names & their dates. I need to pass :id => "current-race" if a condition is present (basically if event is happening now). How could I go about this?

def formatted_race_dates(race)
    link_to (race.homepage) do
      raw("<strong>#{race.name}</strong> <em>#{race_dates_as_string(race)}</em>")
    end
end

now when race.start_date < Date.today && race.end_date > Date.today I’d like to add id="current-race" to the link.

I would normally set up an if/else condition and format it two ways. But seems there must be a Ruby trick I don’t know to simplify something as common adding of a id/class to one link_to in a list? Even without the condition I’m not quite sure where/how to add :id => "current-race".

So many Ruby/Rails tricks I don’t know…everything helps!

  • 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-22T15:10:13+00:00Added an answer on May 22, 2026 at 3:10 pm

    The link_to method takes options for this very reason:

    link_to(race.homepage, :id => 'current-race') do ...
    

    You can even add conditions to trigger it selectively:

    link_to(race.homepage, :id => (race.start_date < Date.today && race.end_date > Date.today) ? 'current-race' : nil) do ...
    

    You can even collapse this if you have a method for Race that indicates if it’s current:

    link_to(race.homepage, :id => race.current? ? 'current-race' : nil) do ...
    

    This is easily implemented in your model and can be used in other places:

    def current?
      self.start_date < Date.today && self.end_date > Date.today
    end
    

    Having it in the model makes it significantly easier to test.

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

Sidebar

Related Questions

I have a new-ish rails 3.1.1 app using sass/compass with compass taking care of
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into
I am creating a map using the new(ish) v3 of the Google Maps API
When updating a DataTable with 1850-ish new rows to a FbDataAdapter I get a
new on ruby and using windows xp and rails 3, i want to send
I'm a new-ish C++ programmer, and I'm doing my first program on my own
I'm trying to use the new(ish) AS3 global error handling class. I am trying
I've started using the new(ish) JUnit Theories feature for parameterizing tests. If your Theory
my apologies if this question doesn't make much sense, but I'm new(ish) to Actionscript,
I'm using PHP's new(ish) Date classes for a calendar/scheduler I'm developing. I am trying

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.