Skip to content

Commit 1f26567

Browse files
committed
minor update
1 parent 6669ec7 commit 1f26567

File tree

8 files changed

+12
-14
lines changed

8 files changed

+12
-14
lines changed

TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* file upload bug
1+
* file upload enhancement
22
* EpicEditor
33
* ajax tag suggestion
44
* model validation

app/controllers/admin.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
get :new_blog, :map => '/admin/blog/new' do
1414
@blog = Blog.new
15-
@attachments = current_account.attachments.where(:blog_id => nil)
15+
@attachments = current_account.attachments.orphan
1616
render 'admin/new_blog'
1717
end
1818

@@ -21,7 +21,6 @@
2121
@blog.account = current_account
2222
if @blog.save
2323
@blog.attach!(current_account)
24-
flash[:notice] = "创建成功"
2524
ping_search_engine(@blog) if APP_CONFIG['blog_search_ping'] # only ping search engine in production environment
2625
redirect url(:blog, :show, :id => @blog.id)
2726
else
@@ -39,7 +38,6 @@
3938
@blog = Blog.find params[:id].to_i
4039
if @blog.update_blog(params[:blog])
4140
@blog.attach!(current_account)
42-
flash[:notice] = '更新成功'
4341
redirect url(:blog, :show, :id => @blog.id)
4442
else
4543
render 'admin/edit_blog'
@@ -49,7 +47,6 @@
4947
delete :blog, :map => '/admin/blog/:id' do
5048
@blog = Blog.find params[:id].to_i
5149
@blog.destroy
52-
flash[:notice] = "删除成功"
5350
redirect url(:blog, :index)
5451
end
5552

app/controllers/home.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
end
2121

2222
get :search do
23-
2423
render 'home/search'
2524
end
2625

2726
get :rss do
28-
content_type :xml
27+
content_type :rss
2928
@blogs = Blog.order('id DESC').limit(10)
3029
APP_CACHE.fetch("#{CACHE_PREFIX}/rss/all") { render 'home/rss' }
3130
end

app/views/admin/_attachment.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="attachment_<%= attachment.id %>">
22
<%= attachment.file.url %>
33
<%= link_to '删除', url(:admin, :attachment, :id => attachment.id), :method => :delete, :remote => true, :confirm => '是否删除附件' %>
4-
<a href="#" onclick="$('#blog_content').insertAtCaret('\n![](<%= attachment.file.url %>)\n');return false;">插入</a>
4+
<a href="#" onclick="window.parent.$('#blog_content').insertAtCaret('\n![](<%= attachment.file.url %>)\n');return false;">插入</a>
55
</div>

app/views/admin/_form.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<td>
1313
<%= form.text_field :tag_list, :placeholder => '用逗号分开,不超过5个' %>
1414
<div class="tag">
15-
<% Blog.tag_counts.each do |tag| %>
15+
<% Blog.cached_tag_cloud.each do |tag| %>
1616
<a href="#" class="tag" rel="tag"><span><%= tag %></span></a>
1717
<% end %>
1818
</div>

config/app_config.example.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ development: &default
33
site_url: 'http://localhost:3000'
44
site_title: 'robbin的自言自语'
55
site_description: '范凯个人网站,记录一些个人博客文章和学习笔记'
6+
blog_search_ping: false
7+
google_cse: '009432631322478558153:qih9evvtgy0'
68

79
test:
810
<<: *default
911

1012
production:
1113
<<: *default
1214
site_url: 'http://robbinfan.com'
15+
blog_search_ping: true

models/attachment.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ class Attachment < ActiveRecord::Base
44

55
belongs_to :account
66
belongs_to :blog
7+
scope :orphan, where(:blog_id => nil)
78
end

models/blog.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def update_blog(param_hash)
3737

3838
def attach!(owner)
3939
self.transaction do
40-
owner.attachments.where(:blog_id => nil).each {|attachment| attachment.update_attribute(:blog_id, self.id) }
40+
owner.attachments.orphan.each {|attachment| attachment.update_attribute(:blog_id, self.id) }
4141
end
4242
end
4343

@@ -63,10 +63,8 @@ def content_cache_key
6363
"#{CACHE_PREFIX}/blog_content/#{self.id}/#{content_updated_at.to_i}"
6464
end
6565

66-
def md_content(mode = :gfm)
67-
APP_CACHE.fetch(content_cache_key) do
68-
GitHub::Markdown.to_html(content, mode)
69-
end
66+
def md_content(mode = :gfm) # cached markdown format blog content
67+
APP_CACHE.fetch(content_cache_key) { GitHub::Markdown.to_html(content, mode) }
7068
end
7169

7270
def self.cached_tag_cloud

0 commit comments

Comments
 (0)