From 80f62e0160614b71ea827697df68379660545685 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Mon, 31 Mar 2014 14:10:54 +0800 Subject: [PATCH] =?UTF-8?q?tag=20=E5=8A=9F=E8=83=BD,=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- app/helpers/application_helper.rb | 3 --- app/models/label.rb | 5 ++--- app/models/post.rb | 4 +++- app/views/blogs/_post.html.slim | 4 ++-- app/views/blogs/index.html.slim | 8 ++++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6ef36d1..80844fb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,6 +8,6 @@ class ApplicationController < ActionController::Base end def format_date(time) - time.strftime("%Y-%m-%d") + time.strftime("%Y.%m.%d") end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ae4c32a..de6be79 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,2 @@ module ApplicationHelper - def format_date(time) - time.strftime("%Y-%m-%d") - end end diff --git a/app/models/label.rb b/app/models/label.rb index 9fab876..30be414 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -2,9 +2,8 @@ class Label include Mongoid::Document include Mongoid::Timestamps - field :type, :type => String + field :name, :type => String has_and_belongs_to_many :post - - validates :type, presence: true + validates :name, presence: true end diff --git a/app/models/post.rb b/app/models/post.rb index 0504903..7195042 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -39,7 +39,9 @@ class Post end def labels_content - self.labels.collect { |label| label.name }.join(", ") + content = self.labels.collect { |label| label.name }.join(", ") + content = '无' if content.blank? + content end def liked_count diff --git a/app/views/blogs/_post.html.slim b/app/views/blogs/_post.html.slim index 4031471..010c5e9 100644 --- a/app/views/blogs/_post.html.slim +++ b/app/views/blogs/_post.html.slim @@ -1,10 +1,10 @@ h2.blog-title #{post.title} p.ptag i.fi-list - span 技术 + span #{post.type} p.ptag i.fi-pricetag-multiple - span 生活, 感悟 + span #{post.labels_content} .content.markdown == post.content_html diff --git a/app/views/blogs/index.html.slim b/app/views/blogs/index.html.slim index d3bea2b..a627789 100644 --- a/app/views/blogs/index.html.slim +++ b/app/views/blogs/index.html.slim @@ -2,16 +2,16 @@ .small-12.large-8.columns h2.blog-title #{@newest.title} p.ptag - | 分类: + i.fi-list span #{@newest.type} p.ptag - | 标签: - span #{@newest.labels.collect{ |label| label.name}.join(', ')} + i.fi-pricetag-multiple + span #{@newest.labels_content} .content.markdown == @newest.sub_content = link_to "阅读全文 >>", blog_path(@newest) - p.published-at 发表于 2014-2-12 + p.published-at 发表于 #{format_date(@newest.created_at)} h4.recent-title RECENT ul.recent-content