commit
4c61e7490b
@ -0,0 +1,121 @@
|
||||
class BlogCommentsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_filter :find_user
|
||||
def index
|
||||
|
||||
end
|
||||
def create
|
||||
if User.current.logged?
|
||||
@article = BlogComment.new
|
||||
@article.author = User.current
|
||||
@article.blog_id = params[:blog_id]
|
||||
@article.safe_attributes = params[:blog_comment]
|
||||
if request.post?
|
||||
@article.save_attachments(params[:attachments])
|
||||
if @article.save
|
||||
# 更新kindeditor上传的图片资源所有者
|
||||
# if params[:asset_id]
|
||||
# ids = params[:asset_id].split(',')
|
||||
# update_kindeditor_assets_owner ids,@article.id,OwnerTypeHelper::BLOGCOMMENT
|
||||
# end
|
||||
render_attachment_warning_if_needed(@article)
|
||||
else
|
||||
end
|
||||
redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'new_base_user'
|
||||
}
|
||||
end
|
||||
end
|
||||
else
|
||||
redirect_to signin_path
|
||||
end
|
||||
end
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
def show
|
||||
@article = BlogComment.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
def update
|
||||
@article = BlogComment.find(params[:id])
|
||||
@article.safe_attributes = params[:blog_comment]
|
||||
@article.save_attachments(params[:attachments])
|
||||
if @article.save
|
||||
render_attachment_warning_if_needed(@article)
|
||||
else
|
||||
end
|
||||
redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
|
||||
end
|
||||
def destroy
|
||||
@article = BlogComment.find(params[:id])
|
||||
if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面
|
||||
@article.children.delete
|
||||
@article.delete
|
||||
redirect_to user_blogs_path(:user_id=>User.current)
|
||||
else
|
||||
root = @article.root
|
||||
@article.delete
|
||||
redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id)
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@article = BlogComment.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
def quote
|
||||
@blogComment = BlogComment.find(params[:id])
|
||||
@subject = @blogComment.title
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}\n> "
|
||||
@temp = BlogComment.new
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)} <br/>#{@blogComment.content.html_safe}</blockquote>".html_safe
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#回复
|
||||
def reply
|
||||
@article = BlogComment.find(params[:id]).root
|
||||
@quote = params[:quote][:quote]
|
||||
@blogComment = BlogComment.new
|
||||
@blogComment.author = User.current
|
||||
@blogComment.blog = Blog.find(params[:blog_id])
|
||||
params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
||||
params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
||||
@blogComment.safe_attributes = params[:blog_comment]
|
||||
@blogComment.content = @quote + @blogComment.content
|
||||
@blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
||||
@article.children << @blogComment
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
|
||||
attachments = Attachment.attach_files(@blogComment, params[:attachments])
|
||||
render_attachment_warning_if_needed(@blogComment)
|
||||
#@article.save
|
||||
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)}
|
||||
format.js
|
||||
end
|
||||
rescue Exception => e #如果上面的代码执行发生异常就捕获
|
||||
flash[:notice] = e.message
|
||||
end
|
||||
|
||||
private
|
||||
def find_user
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module BlogCommentsHelper
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module BlogsHelper
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
class Blog < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :user
|
||||
has_many :articles, :class_name => 'BlogComment', :conditions => "#{BlogComment.table_name}.parent_id IS NULL ", :order => "#{BlogComment.table_name}.created_on DESC"
|
||||
has_many :blog_comments, :dependent => :destroy, :order => "#{BlogComment.table_name}.created_on DESC"
|
||||
belongs_to :last_comment, :class_name => 'BlogComment', :foreign_key => :last_comment_id
|
||||
acts_as_tree :dependent => :nullify
|
||||
#acts_as_list :scope => '(user_id = #{user_id} AND parent_id #{user_id ? = "#{parent_id}" : "IS NULL"})'
|
||||
acts_as_watchable
|
||||
|
||||
validates :name, presence: true, length: {maximum: 30}
|
||||
validates :description, length: {maximum: 255}
|
||||
|
||||
safe_attributes 'name', 'description'
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
class BlogComment < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :blog
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
|
||||
acts_as_tree :counter_cache => :comments_count, :order => "#{BlogComment.table_name}.sticky desc ,#{BlogComment.table_name}.created_on ASC"
|
||||
acts_as_attachable
|
||||
belongs_to :last_reply, :class_name => 'BlogComment', :foreign_key => 'last_comment_id'
|
||||
|
||||
acts_as_watchable
|
||||
|
||||
validates_presence_of :title, :content
|
||||
validates_length_of :title, :maximum => 255
|
||||
#validate :cannot_reply_to_locked_comment, :on => :create
|
||||
safe_attributes 'title', 'content',"sticky", "locked"
|
||||
|
||||
def deleted_attach_able_by? user
|
||||
(user && user.logged? && (self.author == user) ) || user.admin?
|
||||
end
|
||||
|
||||
def project
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue