Module: ECModel

Extended by:
ECModel
Included in:
ECModel
Defined in:
lib/easycomments/ec_model.rb

Instance Method Summary collapse

Instance Method Details

#get_comments(post) ⇒ Object



23
24
25
26
27
# File 'lib/easycomments/ec_model.rb', line 23

def get_comments(post)
  comments = DB[:comments].where(:post => post, :approved => true).all.sort_by{|comment| comment[:id].to_i}.reverse #show latest comment first
  comments = comments.each{|comment| comment[:timestamp] = comment[:timestamp].strftime(TIMESTAMP_FORMAT)}
  MultiJson.dump({:comments => comments})
end

#post_comment(comment) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/easycomments/ec_model.rb', line 7

def post_comment(comment)
  if comment[:body] != "undefined" && comment[:body] != ""
    if ALLOW_ANONYMOUS_POST
      comment[:name] = "Anonymous" if comment[:name] == "undefined" || comment[:name]  == ""
      comment[:email] = "no_email" if comment[:email] == "undefined" || comment[:email]  == ""
      save_comment(comment)
    elsif comment[:name] == "Anonymous" || comment[:name] == "undefined" || comment[:name]  == ""
      MultiJson.dump({:status => "Error : no name provided."})
    else
      save_comment(comment)
    end
  else
   MultiJson.dump({:status => "Error : no comment provided."})
  end
end