Permalink
Browse files

Add RedCloth rendering to comments.

  • Loading branch information...
1 parent cbef2e6 commit 0c496e462d50664bde1f9b853b56abd701565f17 @wfarr wfarr committed Oct 26, 2009
Showing with 11 additions and 7 deletions.
  1. +9 −6 app.rb
  2. +1 −0 models/comment.rb
  3. +1 −1 views/posts/show.haml
View
@@ -13,11 +13,13 @@
end
helpers do
- def cleanup(post)
- post.rendered = RedCloth.new(post.body).to_html
- post.tags_list = post.tags_list.gsub(/ /, "").downcase
- post.tags = post.tags_list.split(",")
- post.save!
+ def cleanup(obj)
+ obj.rendered = RedCloth.new(obj.body).to_html
+ if obj.is_a?(Post)
+ obj.tags_list = obj.tags_list.gsub(/ /, "").downcase
+ obj.tags = obj.tags_list.split(",")
+ end
+ obj.save!
end
end
@@ -62,6 +64,7 @@ def cleanup(post)
end
post '/posts/:post_id/comments' do
- Comment.create(params)
+ @comment = Comment.create(params)
+ cleanup @comment
redirect "/posts/#{params[:post_id]}"
end
View
@@ -3,6 +3,7 @@ class Comment
key :author, String
key :body, String
+ key :rendered, String
timestamps!
belongs_to :post
@@ -11,7 +11,7 @@
=comment.author
said
%br/
- =comment.body
+ =comment.rendered
%form{:action => "/posts/#{@post.id}/comments", :method => 'post'}
%p
%label{:for => 'author'}Author:

0 comments on commit 0c496e4

Please sign in to comment.