Module: CommentsHelper
- Defined in:
- app/helpers/comments_helper.rb
Instance Method Summary collapse
- #comments(options = {}) ⇒ Object
- #comments_display(options = {}) ⇒ Object
- #load_comments(url, options = {}) ⇒ Object
- #strip_url(url) ⇒ Object
Instance Method Details
#comments(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/comments_helper.rb', line 3 def comments( = {}) @comment = Comment.new if current_user @comment.user_email = current_user.email @comment.user_name = current_user.display_name end [:show_form] = [:force_form] || (@page && (@page.allow_anonymous_comments? || (@page.allow_user_comments? && current_user))) [:show_comments] ||= true # already commented? if [:show_form] && current_user && Preference.get_cached(_sid, "one_comment_per_user")=='true' url = strip_url(request.fullpath) [:show_form] = false if Comment.sys(_sid).where(:url=>url).where(:user_id=>current_user.id).count > 0 end render partial:"pages/user_comments", :locals=>{:options=>} end |
#comments_display(options = {}) ⇒ Object
23 24 25 26 |
# File 'app/helpers/comments_helper.rb', line 23 def comments_display( = {}) [:show_form] = false comments() end |
#load_comments(url, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/comments_helper.rb', line 28 def load_comments(url, = {}) surl = strip_url(url) c = Comment.sys(_sid).where(:url=>surl) [:order] ||= "created_at desc" c = c.order([:order]) c = c.where(:is_visible=>1) unless [:dont_visibility] if Preference.get_cached(_sid, "moderate_comments")!='false' c = c.where(:is_moderated=>1) unless [:dont_moderation] end unless [:no_pagination] c = c.page(params[:cpage]) c = c.per([:per] || 3) else c.all end end |
#strip_url(url) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/comments_helper.rb', line 45 def strip_url(url) if url =~ /\?cpage\=\d+$/ # if cpage=X is the only parameter, remove it return url.sub(/\?cpage\=\d+/, '') elsif url =~ /cpage\=\d+/ # if cpage=X is a parameter, remove it return url.sub(/cpage\=\d+/, '') else return url end end |