Class: BlogController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- BlogController
- Defined in:
- app/controllers/blog_controller.rb
Instance Method Summary collapse
- #archive ⇒ Object
- #category ⇒ Object
- #create_comment ⇒ Object
-
#filter ⇒ Object
The sole purpose of this action is to redirect from a POST to an seo-friendly url.
- #index ⇒ Object
- #show ⇒ Object
Instance Method Details
#archive ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/blog_controller.rb', line 84 def archive if Spud::Core.config.multisite_mode_enabled @posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date]) else @posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date]) end respond_with @posts do |format| format.html { render 'index' } end end |
#category ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/blog_controller.rb', line 56 def category page = 1 if params[:page].blank? == false page = params[:page].to_i if page.to_s != params[:page].to_s if(page > 1) redirect_to blog_category_path(:page => page),:status => :moved_permanently and return else redirect_to blog_category_path(:page => nil),:status => :moved_permanently and return end end end if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name]) if Spud::Core.config.multisite_mode_enabled @posts = @post_category.posts_with_children.public_blog_posts(page, Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date]) else @posts = @post_category.posts_with_children.public_blog_posts(page, Spud::Blog.config.posts_per_page).from_archive(params[:archive_date]) end else redirect_to blog_path return end respond_with @posts do |format| format.html { render 'index' } end end |
#create_comment ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/blog_controller.rb', line 102 def create_comment unless params[:comment_validation].blank? # trap spam bots render :nothing => true return end @post = SpudPost.find(params[:id]) if @post.blank? flash[:error] = "Post not found!" redirect_to blog_path and return false end @comment = @post.comments.new(comment_params) @comment.user_agent = request.env["HTTP_USER_AGENT"] @comment.user_ip = request.remote_ip @comment.referrer = request.referrer @comment.approved = true @comment.permalink = blog_post_url(@post.url_name) flash[:notice] = 'Your comment has been posted.' if @comment.save respond_with @comment do |format| format.html { redirect_to blog_post_path(@post.url_name, :anchor => 'spud_post_comment_form') } end end |
#filter ⇒ Object
The sole purpose of this action is to redirect from a POST to an seo-friendly url
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/blog_controller.rb', line 44 def filter if !params[:category_url_name].blank? && !params[:archive_date].blank? redirect_to blog_category_archive_path(params[:category_url_name], params[:archive_date]) elsif !params[:category_url_name].blank? redirect_to blog_category_path(params[:category_url_name]) elsif !params[:archive_date].blank? redirect_to blog_archive_path(params[:archive_date]) else redirect_to blog_path end end |
#index ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/blog_controller.rb', line 23 def index page = 1 if params[:page].blank? == false page = params[:page].to_i if page.to_s != params[:page].to_s if(page > 1) redirect_to blog_path(:page => page),:status => :moved_permanently and return else redirect_to blog_path(:page => nil),:status => :moved_permanently and return end end end @posts = SpudPost.public_blog_posts(page, Spud::Blog.config.posts_per_page) if Spud::Core.config.multisite_mode_enabled @posts = @posts.for_spud_site(current_site_id) end respond_with @posts end |
#show ⇒ Object
95 96 97 98 99 100 |
# File 'app/controllers/blog_controller.rb', line 95 def show if @post.comments_enabled @comment = SpudPostComment.new(:spud_post_id => params[:id]) end respond_with @post end |