label added, index modified

This commit is contained in:
windy 2014-03-29 23:42:30 +08:00
parent 5800f6f31a
commit b36619b3d1
6 changed files with 52 additions and 20 deletions

View File

@ -32,7 +32,7 @@ class Admin::PostsController < ApplicationController
md = Redcarpet::Markdown.new(rd, :autolink=>true)
render :text => md.render(text)
end
def post_params
params.require(:post).permit(:title, :content, :type)
end

10
app/models/label.rb Normal file
View File

@ -0,0 +1,10 @@
class Label
include Mongoid::Document
include Mongoid::Timestamps
field :type, :type => String
has_and_belongs_to_many :post
validates :type, presence: true
end

View File

@ -10,9 +10,10 @@ class Post
field :content, :type => String
field :type, :type=> String
field :visited_count, :type=>Integer, :default=>0
has_many :comments
has_and_belongs_to_many :labels
validates :title, :presence=>true, :uniqueness=> true
validates :content, :presence=>true, :length => { :minimum=> 30 }
validates :type, :presence=>true, :inclusion => { :in => [ TECH, LIFE, CREATOR ] }
@ -28,4 +29,11 @@ class Post
self.save
self.visited_count
end
def sub_content
rd = Redcarpet::Render::HTML.new(:hard_wrap=>true)
md = Redcarpet::Markdown.new(rd, :autolink=>true)
sub_cont = md.render(self.content)
HTML_Truncator.truncate(sub_cont,100)
end
end

View File

@ -6,32 +6,21 @@
span #{@newest.type}
p.ptag
| 标签:
span 生活, 感悟
span #{@newest.labels.collect{ |label| label.name}.join(', ')}
.content
p 没错, 科学只是哲学的一个部分, 所以此书给我最大的收获是, 科学只是一种实用主义. 只是这种实用主义更纯粹些:
p
| 1. 任何公理都值得怀疑
| 2. 能够验证与重复
== @newest.sub_content
p 瞧, 第 2 点的感觉就是说, 太阳一直东方升起, 这就是科学, 因为我们一直在重复这个结论. 但是, 我们知道, 1000万年后, 我们可能就再也看不到太阳了, 所以这个结论还需要修正. 这就是科学的本质.
p 再举个历史的例子:
p
| 1. 地球是平的
| 2. 地球是圆的
| 3. 地球是椭圆的
p.read-more 阅读全文 >>
= link_to "阅读全文 >>", blog_path(@newest)
p.published-at 发表于 2014-2-12
h4.recent-title RECENT
ul.recent-content
li 你是我的朋友
li 该更新装备了
- @recent.each do |re|
li = link_to "#{re.title}",blog_path(re)
.large-3.columns.large-offset-1
h4 WELCOME
hr
p 我是李亚飞, WinDy 是我的网名, 又名风一样的男子.
p 我是李亚飞, WinDy 是我的网名.
h4 ABOUTME
hr

View File

@ -41,4 +41,24 @@ describe BlogsController do
assigns[:comments][1].email.should == 'liuzhen@.com'
end
it 'test show method' do
post = Post.new(title: 'a123', content: '123'*20, type: Post::TECH)
post.save!
a = Comment.new(name: '1',content: '2432423',email: '22@.com')
a.post = post
a.save!
b = Comment.new(name: '2',content: 'iloveyou',email: 'liuzhen@.com')
b.post = post
b.save!
label = Label.new(type: '生活')
post.labels << label
post.save!
get :show, id: post.id
assigns[:comments][0].name.should == '1'
assigns[:comments][0].content.should == '2432423'
assigns[:comments][0].email.should == '22@.com'
assigns[:comments][1].name.should == '2'
assigns[:comments][1].content.should == 'iloveyou'
assigns[:comments][1].email.should == 'liuzhen@.com'
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Label do
end