Class: Blog::PostsController

Inherits:
Spree::BaseController
  • Object
show all
Defined in:
app/controllers/blog/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#archiveObject



46
47
48
# File 'app/controllers/blog/posts_controller.rb', line 46

def archive
	@posts = Post.live.all
end

#get_sidebarObject



50
51
52
53
54
# File 'app/controllers/blog/posts_controller.rb', line 50

def get_sidebar
  @archive_posts = Post.live.limit(10)
  @post_categories = PostCategory.all
  get_tags
end

#get_tagsObject



56
57
58
# File 'app/controllers/blog/posts_controller.rb', line 56

def get_tags
  @tags = Post.live.tag_counts.order('count DESC').limit(25)
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/blog/posts_controller.rb', line 7

def index
  @posts_by_month = Post.live.limit(50).group_by { |post| post.posted_at.strftime("%B %Y") }
  scope = Post.live
  if params[:year].present?
    year  = params[:year].to_i
    month = 1
    day   = 1  
    if has_month = params[:month].present?
      if has_day = params[:day].present?
        day  = params[:day].to_i
      end
      month = params[:month].to_i
    end
    start = Date.new(year, month, day)
    stop  = start + 1.year
    if has_month
      stop = start + 1.month
      if has_day
        stop = start + 1.day
      end
    end    
    scope = scope.where("posted_at >= ? AND posted_at <= ?", start, stop)
  end
  @posts = scope.page(params[:page]).per(Post.per_page)
end

#searchObject



33
34
35
36
37
38
# File 'app/controllers/blog/posts_controller.rb', line 33

def search
	query = params[:query].gsub(/%46/, '.')	
	@posts = Post.live.tagged_with(query).page(params[:page]).per(Post.per_page)
	get_tags		
	render :template => 'blog/posts/index'
end

#showObject



40
41
42
43
44
# File 'app/controllers/blog/posts_controller.rb', line 40

def show
  @blog_config = BlogConfiguration.current
  @post = Post.live.includes(:tags, :images, :products).find_by_path(params[:id]) rescue nil
  return redirect_to archive_posts_path unless @post
end