Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

helper caching issue

#2353

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.

Reported by Greg Donald · March 26th, 2009 @ 07:28 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. thedarkone
    thedarkone

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

    March 27th, 2009 @ 03:11 PM

  2. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.2, helper to 2.3.2, bugmash, helper

    August 5th, 2009 @ 03:50 PM

  3. Nick Quaranto
    Nick Quaranto

    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)
    

    August 8th, 2009 @ 11:50 PM

  4. Kieran P
    Kieran P

    -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.

    August 9th, 2009 @ 04:58 AM

  5. Rizwan Reza
    Rizwan Reza

    not reproducible

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

    August 9th, 2009 @ 04:23 PM

  6. Elad Meidar
    Elad Meidar

    -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.

    August 9th, 2009 @ 05:55 PM

  7. Dan Croak
    Dan Croak

    -1 should use date conversions

    August 9th, 2009 @ 06:00 PM

  8. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to invalid
    • Tag changed from 2.3.2, bugmash, helper to 2.3.2, helper

    August 10th, 2009 @ 02:44 AM