Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
allow the user to allow comments or not on a page, blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Jan 26, 2009
1 parent b92cb6b commit 5aa3349
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/pages_controller.rb
Expand Up @@ -31,6 +31,7 @@ def edit
end

def update
@page.settings = params[:settings]
if @page.update_attributes(params[:page])
handle_publishing_workflow
flash.now[:message] = 'Page Updated Successfully'
Expand All @@ -56,6 +57,7 @@ def new

def create
@page.name = @page.name.gsub(' ', '_')
@page.settings = params[:settings]
if @page.save
attach_page_plugins
message = 'Page Added Successfully'
Expand Down
18 changes: 12 additions & 6 deletions app/helpers/comments_helper.rb
@@ -1,21 +1,27 @@
module CommentsHelper
def show_comments_for(commentable)
render :partial => 'shared/comments', :locals => { :commentable => commentable }
if commentable.settings["allow_comments"]
render :partial => 'shared/comments', :locals => { :commentable => commentable }
end
end

def show_comment_form_for(commentable, options={})
raise "No return path specified" unless options[:return_path]
comment = Comment.new
comment.commentable = commentable
render :partial => 'shared/comment_form', :locals => { :comment => comment, :commentable => commentable, :return_path => options[:return_path] }
if commentable.settings["allow_comments"]
comment = Comment.new
comment.commentable = commentable
render :partial => 'shared/comment_form', :locals => { :comment => comment, :commentable => commentable, :return_path => options[:return_path] }
end
end

def show_comment(comment)
render :partial => 'shared/comment', :locals => { :comment => comment }
end

def show_comment_info_link_for(commentable, options={})
rause "No path specified" unless options[:path]
render :partial => 'shared/comment_info_link', :locals => { :commentable => commentable, :path => options[:path] }
raise "No path specified" unless options[:path]
if commentable.settings["allow_comments"]
render :partial => 'shared/comment_info_link', :locals => { :commentable => commentable, :path => options[:path] }
end
end
end
1 change: 1 addition & 0 deletions app/models/page.rb
Expand Up @@ -23,6 +23,7 @@ class Page < ActiveRecord::Base
include AASM
include ActionView::Helpers::DateHelper
acts_as_commentable
has_settings

named_scope :visible, :conditions => ["(expires_on > ? OR expires_on IS NULL) AND published = ? AND (publish_at <= ? OR publish_at IS NULL )", Time.now.getgm, true, Time.now.getgm]
named_scope :self_and_siblings, lambda {|page| {:conditions => ["parent_id = ?", page.parent_id], :order => 'page_order'}}
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/pages/_form.html.erb
Expand Up @@ -8,6 +8,7 @@
<%= form_row "Publish On", calendar_date_select_tag('page[publish_at]', Time.now.strftime("%Y-%m-%d %I:%M %P"), :time => true, :minute_interval => 5) %>
<%= form_row "Expires On", calendar_date_select_tag('page[expires_on]', @page.expires_on, :time => true, :minute_interval => 5) %>
<%= form_row "Status", @page.status, :field_options => { :id => 'status' } %>
<%= form_row "Allow Comments", check_box_tag("settings[allow_comments]", "on", @page.settings["allow_comments"] == "on") %>
</table>
<div class="advanced_options">
<% toggle_content_box "Advanced Options" do %>
Expand Down
Expand Up @@ -23,6 +23,7 @@ def new
end

def create
@blog_post.settings = params[:settings]
if @blog_post.save
flash[:notice] = "Blog Post was created successfully."
redirect_to admin_blog_posts_path
Expand All @@ -39,6 +40,7 @@ def edit
end

def update
@blog_post.settings = params[:settings]
if @blog_post.update_attributes(params[:blog_post])
flash[:notice] = "Blog Post has been updated."
redirect_to admin_blog_post_path(@blog_post)
Expand Down
Expand Up @@ -5,6 +5,7 @@ class BlogPost < ActiveRecord::Base
acts_as_url :title
stampable
acts_as_commentable
has_settings

validates_uniqueness_of :url

Expand Down
Expand Up @@ -2,4 +2,6 @@
<%= form_heading "Post", fckeditor_textarea(:blog_post, :contents, :toolbarSet => 'Simple', :width => '100%', :height => '400px') -%>
<br />
<%= form_heading "Tags", f.text_field(:tag_list) -%>
<%= form_heading "Allow Comments?", check_box_tag("settings[allow_comments]", "on", @blog_post.settings["allow_comments"] == "on") -%>
<%= hidden_field_tag "settings[ignoreme]" %>
<br />
2 changes: 1 addition & 1 deletion vendor/plugins/has_settings/lib/has_settings.rb
Expand Up @@ -27,7 +27,7 @@ def has_settings

define_method "settings" do |*args|
@the_has_settings_setting ||= get_has_settings_setting
@the_has_settings_setting.settings
@the_has_settings_setting.settings || {}
end

define_method "settings=" do |the_settings|
Expand Down

0 comments on commit 5aa3349

Please sign in to comment.