This project is archived and is in readonly mode.

#2353 ✓invalid
Greg Donald

helper caching issue

Reported by Greg Donald | March 26th, 2009 @ 07:28 PM | in 2.x

I have a helper:

def pretty_datetime( dt ) dt.strftime( "%b %d, %Y %I:%m%p" ) end

and I have a partial that uses the helper like this:

<%= pretty_datetime alert.updated_at %>

The problem is when I update the record the previous updated_at value is still being displayed.

When I don't use the helper I see the updated_at value change every time.

<%= alert.updated_at %>

When I put the helper call back again, the partial again shows me the previous updated_at value, even after multiple updates and me taking it away and putting it back multiple times. Even if I restart the server I'm still seeing the old updated_at values from when the record was first created. I see the values changing in the database when I update the record so I know the problem isn't there.

This is in development mode, Rails 2.3.2.

Comments and changes to this ticket

  • thedarkone

    thedarkone March 27th, 2009 @ 03:11 PM

    Can you create smallish 1 controller 1 helper app on github to demonstrate the issue?

  • CancelProfileIsBroken

    CancelProfileIsBroken August 5th, 2009 @ 03:50 PM

    • Tag changed from 2.3.2, helper to 2.3.2, bugmash, helper
  • Nick Quaranto

    Nick Quaranto August 8th, 2009 @ 11:50 PM

    Invalid. First off, I think because you're trying to display updated_at, when you edit it, ActiveRecord tries to update it like it's a timestamp. Also, I think this is not the best way to show a custom date format. You should instead set a custom format in an initializer, like so:

    ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
    :my_custom_format => “%A %B %d, %Y”
    )
    

    Then in your view:

      @user.updated_at.to_formatted_s(:my_custom_format)
    
  • Kieran P

    Kieran P August 9th, 2009 @ 04:58 AM

    -1 I agree with Nick. I've never run into this issue with apps I've worked on, and using active support is much better suited to this task than cluttering your helpers. Double check the method isn't memoized either.

  • Rizwan Reza

    Rizwan Reza August 9th, 2009 @ 04:23 PM

    not reproducible

    -1 Agreed with Nick. The problem lies in defining that pretty_datetime. Invalid.

  • Elad Meidar

    Elad Meidar August 9th, 2009 @ 05:55 PM

    -1 was unable to reproduce. I agree with nick, use of #to_s with a custom format is probably the consist way to approach this.

  • Dan Croak

    Dan Croak August 9th, 2009 @ 06:00 PM

    -1 should use date conversions

  • CancelProfileIsBroken

    CancelProfileIsBroken August 10th, 2009 @ 02:44 AM

    • State changed from “new” to “invalid”
    • Tag changed from 2.3.2, bugmash, helper to 2.3.2, helper

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags

Pages