Skip to content

Instantly share code, notes, and snippets.

@gen1321
Created September 9, 2015 20:02
Show Gist options
  • Save gen1321/dfee51d6c21c874e3161 to your computer and use it in GitHub Desktop.
Save gen1321/dfee51d6c21c874e3161 to your computer and use it in GitHub Desktop.
def comment
@comment = @post.comments.create(comment_params)
@comment[:state]= "approved"
@comment[:spam]= false
if @comment.valid?
if Comment::Moderation.enabled? or @comment.ham?
begin
CommentMailer.notification(@comment, request).deliver_now
rescue
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
end
end
if Comment::Moderation.enabled?
flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id])
else
flash[:notice] = t('thank_you', :scope => 'refinery.blog.posts.comments')
redirect_to refinery.blog_post_url(params[:id],
:anchor => "comment-#{@comment.to_param}")
end
else
render :show
end
@comment[:state]= "approved"
end
def thank
byebug
@comment= Refinery::Blog::Comment.find(params[:id])
current_item = @comment
@thank = current_item.thank.find_by_user_id(getCuser)
unless @thank
@thank = thank.create(:user_id => spree_current_user.id, :value => 0)
current_item.thank << @thank
end
@thank.value += 1 unless @thank.value == 1
@thank.save
respond_to do |format|
format.html
format.js
end
end
def dislike
get_thank
@thank.value -= 1 unless @thank.value == -1
@thank.save
respond_to do |format|
format.html
format.js
end
end
def archive
if params[:month].present?
date = "#{params[:month]}/#{params[:year]}"
archive_date = Time.parse(date)
@date_title = ::I18n.l(archive_date, :format => '%B %Y')
@posts = Post.live.by_month(archive_date).page(params[:page])
else
date = "01/#{params[:year]}"
archive_date = Time.parse(date)
@date_title = ::I18n.l(archive_date, :format => '%Y')
@posts = Post.live.by_year(archive_date).page(params[:page])
end
respond_with (@posts)
end
def tagged
@tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
@tag_name = @tag.name
@posts = Post.live.tagged_with(@tag_name).page(params[:page])
end
private
def comment_params
varfordebug = params.require(:comment).permit(:message )
varfordebug[:name] = spree_current_user.FirstName + " " + spree_current_user.LastName
varfordebug[:email]= spree_current_user.email
varfordebug[:state]= "approved"
varfordebug[:spam]= false
varfordebug[:Spree_User_id]=spree_current_user.id
return varfordebug
end
private
def get_thank
byebug
@comment= Refinery::Blog::Comment.find(params[:id])
current_item = @comment
@thank = current_item.thank.find_by_user_id(getCuser)
unless @thank
@thank = thank.create(:user_id => spree_current_user.id, :value => 0)
current_item.thank << @thank
end
end
private
def getCuser
spree_current_user.id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment