On 17 Mar., 07:56, Don French <[email protected]> wrote:
> I have a page that requires a lot of DB access to create a section of
> it, but that section does not change very often. I know how to cache
> the fragment in the view, but the db is still accessed in the
> controller. I watched the railscasts on fragment caching and he does
> it by moving the logic to the model.  Is that the only way to do it?
> The part of the page that changes on every display is the advertising
> so I can not cache the entire page.

You can use the #fragment_exists? method in your controller action.
This allows you to avoid querying the database if it's not neseccary.

def action
  unless fragment_exists? "fragment"
    # Execute SQL here...
  end
end

--
Cheers,
David Knorr
http://twitter.com/rubyguy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to