Forum: Ruby on Rails Prevent caching of helper method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2009-05-31 14:12
(Received via mailing list)
Hi,
I have a helper method to get a date from a cookie (in application
helper) that looks like this:

def getToday
   if(cookies[:date])
    cookies[:date].to_date
  else
    Date.today
  end
end

I set the cooke date using a before_filter method in the application
controller, reading a GET param:

before_filter :save_today_as_cookie

  def save_today_as_cookie

    if params[:d]
      cookies.delete :date
      cookies[:date] = {
        :value => params[:d],
        :expires => 1.hours.from_now
      }
    end
  end

This works fine, but if I want to change the date by passing a new
date parameter, I have to reload the page twice that it takes affect.

The cookie changes instantly. It seems to me, that the result of the
helper function is cached for one more load.
Setting expiring headers or etags did not help.

I'm using Rails 2.3.2 and no special cache plugin/gem/configuration.


Regards,

Chris
Frederick C. (Guest)
on 2009-05-31 15:35
(Received via mailing list)
On May 31, 11:12 am, Chris <removed_email_address@domain.invalid> wrote:
> The cookie changes instantly. It seems to me, that the result of the
> helper function is cached for one more load.
> Setting expiring headers or etags did not help.
>
It's not your helper function, it's the cookies method:
https://rails.lighthouseapp.com/projects/8994/tickets/2733

Fred
Chris (Guest)
on 2009-05-31 18:35
(Received via mailing list)
Ah, thanks for the hint. So I'll have to update the actionpack/lib/
action_controller/base/cookies.rb file, right?

Or what is the recommended way to fix problems in the rails core? (I'm
pretty new to rails)

Regards,

Chris
Chris (Guest)
on 2009-05-31 18:38
(Received via mailing list)
I mean is there a way to patch/overwrite this using a plugin or
something? I don't want to touch the core classes, if not necessary.
Frederick C. (Guest)
on 2009-05-31 18:59
(Received via mailing list)
On May 31, 3:37 pm, Chris <removed_email_address@domain.invalid> wrote:
> I mean is there a way to patch/overwrite this using a plugin or
> something? I don't want to touch the core classes, if not necessary.

You could just monkey patch it using the patch on that ticket as a
guide.

Fred
Chris (Guest)
on 2009-06-01 12:03
(Received via mailing list)
Ah, I see. Thanks!

On May 31, 4:57 pm, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.