Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Page cache to caches_page.
Browse files Browse the repository at this point in the history
Fix setting bug.
  • Loading branch information
huacnlee committed Feb 15, 2012
1 parent 4e07d59 commit e06f1be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
@@ -1,6 +1,6 @@
# coding: utf-8
class HomeController < ApplicationController
caches_action :show
caches_page :show
caches_action :share, :cache_path => Proc.new { |c| "home/share" }, :expires_in => 1.days

def index
Expand Down
7 changes: 4 additions & 3 deletions app/models/setting.rb
Expand Up @@ -2,9 +2,10 @@
class Setting < ActiveRecord::Base

def self.find_create
Rails.cache.fetch("models/setting1") do
if not setting = first
create(:site_name => "PersonLab Demo", :sub_title => "This is an person website build by Ruby on Rails.",
Rails.cache.fetch("models/setting2") do
setting = first
if setting.blank?
setting = create(:site_name => "PersonLab Demo", :sub_title => "This is an person website build by Ruby on Rails.",
:meta_keywords => "personlab,ruby on rails",
:email => "huacnlee@gmail.com",
:meta_description => "This is an person website build by Ruby on Rails.",
Expand Down
2 changes: 1 addition & 1 deletion app/sweepers/page_sweeper.rb
Expand Up @@ -10,6 +10,6 @@ def after_destroy(page)
end

def clear_page_cache(page)
expire_action page_path(page.slug)
expire_page page_path(page.slug)
end
end
6 changes: 2 additions & 4 deletions app/views/layouts/application.html.erb
Expand Up @@ -15,8 +15,6 @@
<%= stylesheet_link_tag "application", :cache => "cached_application" %>
<%= yield :styles -%>
<%= auto_discovery_link_tag(:rss,(@setting.feed_url || rss_blogs_url),:title => '定阅最新博客') %>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<%= javascript_include_tag "rails","will_paginate","common", :cache => "cached_application" %>
</head>
<body>
<div id="body">
Expand Down Expand Up @@ -55,8 +53,9 @@
</p>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<%= javascript_include_tag "rails","will_paginate","common", :cache => "cached_application" %>
<%= yield :scripts %>

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '<%= @setting.disqus_shortname %>'; // required: replace example with your forum shortname
Expand All @@ -69,7 +68,6 @@
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>

<% if !@setting.google_analytics_id.blank? %>
<script type='text/javascript'>var _gaq = _gaq || []; _gaq.push(['_setAccount', '<%= @setting.google_analytics_id %>']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>
<% end %>
Expand Down

0 comments on commit e06f1be

Please sign in to comment.