task 2


SUBMITTED BY: Guest

DATE: Aug. 3, 2013, 3:18 p.m.

FORMAT: Ruby

SIZE: 780 Bytes

HITS: 1022

  1. module Commentable
  2. def verify_comment_permissions
  3. unless member?
  4. flash[:notice] = t(:'comments.not_a_member')
  5. redirect_to root_without_cache_path
  6. end
  7. end
  8. def commenting_allowed?
  9. member?
  10. end
  11. def add_comment_to(object, opts = {})
  12. return unless commenting_allowed?
  13. @comment = Comment.new(params[:comment])
  14. @comment.user = current_user
  15. @comment.ip = request.remote_ip
  16. @comment.country_name_id = visitor_country_name_id
  17. @comment.approved = false
  18. @comment.commentable = object
  19. success = @comment.save
  20. flash[:notice] = t(:'comments.successfully_created') if success
  21. success
  22. end
  23. end

comments powered by Disqus