Permalink
Browse files

Fix setting page bug;

Move google_analytics/footer_html config to Cpanel Setting.
  • Loading branch information...
1 parent 21e02c4 commit 7edfe00eaa37d381314b94c0f302425fa490a294 @huacnlee committed Nov 29, 2011
@@ -5,7 +5,7 @@ class Cpanel::SettingsController < Cpanel::ApplicationController
# GET /settings
# GET /settings.xml
def index
- @setting = Setting.find_create
+ @setting = Setting.first
if request.put?
if @setting.update_attributes(params[:setting])
@@ -4,7 +4,6 @@ class TestMailer < ActionMailer::Base
def try(to,subject)
subject "#{subject}"
recipients to
- from "no-reply@#{APP_DOMAIN}"
sent_on Time.now
body subject
end
View
@@ -2,22 +2,20 @@
class Setting < ActiveRecord::Base
def self.find_create
- @setting = Rails.cache.read("models/setting1").dup
- if @setting.blank?
- @setting = first
- if not @setting
- @setting = new(:site_name => "PersonLab Demo", :sub_title => "This is an person website build by Ruby on Rails.",
+ 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.",
:meta_keywords => "personlab,ruby on rails",
:email => "huacnlee@gmail.com",
:meta_description => "This is an person website build by Ruby on Rails.",
:twitter_id => "huacnlee",
- :disqus_shortname => "foobar",
+ :disqus_shortname => "foobar",
:google_reader_id => "08982619185204047523",
+ :google_analytics_id => '',
+ :footer_html => '',
:home_show => '')
- @setting.save
end
- Rails.cache.write("models/setting1",@setting)
+ setting
end
- return @setting
end
end
@@ -29,6 +29,10 @@
<td>http://www.google.com/reader/shared/<%= f.text_field :google_reader_id, :class => "text short" %></td>
</tr>
<tr class="row">
+ <td class="field">Google Analytics Id</td>
+ <td><%= f.text_field :google_analytics_id, :class => "text short" %></td>
+ </tr>
+ <tr class="row">
<td class="field">Meta Keywords</td>
<td><%= f.text_field :meta_keywords, :class => "text long" %></td>
</tr>
@@ -44,6 +48,10 @@
<%= f.text_area :home_show, :class => "text long" %>
</td>
</tr>
+ <tr class="row">
+ <td class="field">Footer HTML</td>
+ <td><%= f.text_area :footer_html, :class => "text long" %></td>
+ </tr>
<tr class="row buttons">
<td class="field"></td>
<td><%= f.submit '保存', :class => "submit" %></td>
@@ -14,7 +14,7 @@
<link href='http://fonts.googleapis.com/css?family=Crimson+Text&subset=latin' rel='stylesheet' type='text/css'>
<%= stylesheet_link_tag "application", :cache => "cached_application" %>
<%= yield :styles -%>
- <%= auto_discovery_link_tag(:rss,(FEED_URL || rss_blogs_url),:title => '定阅最新博客') %>
+ <%= 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>
@@ -35,7 +35,7 @@
<div id="sidebar">
<div class="section">
<h2>订阅我的博客</h2>
- <div class="icons"><a href="<%= (FEED_URL || rss_blogs_url) %>"><%= image_tag("feed-big.png") %></a></div>
+ <div class="icons"><a href="<%= (@setting.feed_url || rss_blogs_url) %>"><%= image_tag("feed-big.png") %></a></div>
</div>
<div class="section">
<%= raw @setting.home_show %>
@@ -44,9 +44,9 @@
<%= yield %>
</div>
<div id="footer">
- <% if !FOOTER_HTML.blank? %>
+ <% if !@setting.footer_html.blank? %>
<p>
- <%=raw FOOTER_HTML %>
+ <%=raw @setting.footer_html %>
</p>
<% end %>
<p class="copyright">
@@ -70,8 +70,8 @@
}());
</script>
-<% if !GOOGLE_ANALYTICS_ID.blank? %>
-<script type='text/javascript'>var _gaq = _gaq || []; _gaq.push(['_setAccount', '<%= 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>
+<% 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 %>
</body>
</html>
View
@@ -25,7 +25,7 @@ class Application < Rails::Application
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Set Time.zone default to the specified zone\ and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.time_zone = 'Beijing'
@@ -45,21 +45,3 @@ class Application < Rails::Application
end
end
-
-
-
-# *****************************************************************
-# ********************* CUSTOM CONFIGS **********************
-# *****************************************************************
-# you app domain
-APP_DOMAIN = 'huacnlee.com'
-
-# custom feed url, set false to use system feed url
-FEED_URL = false
-
-# Google Analytics Account ID
-GOOGLE_ANALYTICS_ID = "UA-9745660-1"
-
-# Custom html code in footer.
-FOOTER_HTML = ""
-
@@ -0,0 +1,13 @@
+class AddGoogleAnalyticsIdToSettings < ActiveRecord::Migration
+ def self.up
+ add_column :settings, :google_analytics_id, :string
+ add_column :settings, :footer_html, :text
+ add_column :settings, :feed_url, :string
+ end
+
+ def self.down
+ remove_column :settings, :feed_url
+ remove_column :settings, :footer_html
+ remove_column :settings, :google_analytics_id
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111025044849) do
+ActiveRecord::Schema.define(:version => 20111129024726) do
create_table "categories", :force => true do |t|
t.string "name", :null => false
@@ -78,6 +78,9 @@
t.string "twitter_id"
t.string "google_reader_id"
t.string "disqus_shortname"
+ t.string "google_analytics_id"
+ t.text "footer_html"
+ t.string "feed_url"
end
create_table "sitemap_settings", :force => true do |t|
@@ -122,6 +125,7 @@
end
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
+ add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", :force => true do |t|
t.string "name"

0 comments on commit 7edfe00

Please sign in to comment.