1

This seems like it should not be that hard but I am trying to figure out how to create a 'snapshot' or 'locked' view from one on my views. This view currently is dynamic but I want to lock it so that any changes I make will not propagate until I want them too.

This would be a front facing page that should not get updated until I choose to update it such as by timestamping a field like updated_lock or something to that effect.

Any ideas?

Thanks, BR

Bob Roberts
  • 1,013
  • 9
  • 15

1 Answers1

0

You might try caches_action in your controller. It will create the static version and save it. You could either create it in dev and checkin, or have it generated in production. You'd need to fine a way to delete it in production if it's not checked in. Requires caching to be turned on.

If you are OK with checking it in - you can always save from the browser.

Basically - if there is a file in public at the same location as the view, it will be served instead of the dynamic one.

Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70
  • Yes, I was thinking about maybe caching. If I set that to never expire will it not update if I have new data or change the views? – Bob Roberts Jan 14 '14 at 02:21
  • 1
    You have a couple options for caching. Sorry, I mistyped above, what you really want is page caching, not action caching here. In that case, you'd use `caches_page`. In rails 4, this will be in a gem if that's the way you want to go. – Mark Swardstrom Jan 14 '14 at 22:57
  • Thanks, I will take a look at that and see what it does. – Bob Roberts Jan 15 '14 at 17:39
  • OK, I found that caches_page ALMOST does exactly what I want. This is a reach, but is there a way to cache the page WITHOUT visiting it? In other words, set a view to use the caches_page and set the cache before anybody goes to that page? – Bob Roberts Mar 26 '14 at 01:59
  • Probably - I haven't done this, but you'd want to render a page and save it as a file. You could likely do this through a rake task/cron job. A quick google showed others doing this, eg: http://stackoverflow.com/questions/4262044/rails-3-how-to-render-erb-template-in-rake-task – Mark Swardstrom Mar 26 '14 at 15:38
  • This might work. That is essentially what happens when you visit the page and it is cached. I will try this out :) – Bob Roberts Mar 26 '14 at 20:22
  • I marked you as the correct answer. In a round about way it was your answers and some more things that made it work... [see here](http://bob-roberts.net/2014/03/30/pre-caching-a-page-in-rails/) – Bob Roberts Mar 31 '14 at 00:26