Module: ECModel
- Extended by:
- ECModel
- Includes:
- Pagination
- Included in:
- ECModel
- Defined in:
- lib/easycomments/ec_model.rb
Instance Method Summary collapse
Instance Method Details
#get_comments(post, page_num) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/easycomments/ec_model.rb', line 24 def get_comments(post, page_num) if PAGINATE comments = DB[:comments].where(:post => post, :approved => true).reverse(Sequel.asc(:timestamp)).page(page_num).all count = DB[:comments].where(:post => post).page(page_num).page_count comments = comments.each{|comment| comment[:timestamp] = comment[:timestamp].strftime(TIMESTAMP_FORMAT)} page_num = page_num.to_i page_num = 1 if page_num < 1 response = {:comments => comments, :page => page_num.to_i, :total_pages => count} else comments = DB[:comments].where(:post => post, :approved => true).reverse(Sequel.asc(:timestamp)).all comments = comments.each{|comment| comment[:timestamp] = comment[:timestamp].strftime(TIMESTAMP_FORMAT)} response = {:comments => comments} end MultiJson.dump(response) end |
#post_comment(comment) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/easycomments/ec_model.rb', line 8 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 |