Class: BlogController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/active_admin/blog/templates/controllers/blog_controller.rb

Instance Method Summary collapse

Instance Method Details

#feedObject



26
27
28
29
30
31
32
33
# File 'lib/generators/active_admin/blog/templates/controllers/blog_controller.rb', line 26

def feed
  @posts = BlogPost.published

  respond_to do |format|
    format.rss { render :layout => false } #index.rss.builder
    format.all { head :not_found }
  end
end

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/active_admin/blog/templates/controllers/blog_controller.rb', line 2

def index
  category_slug = params[:category]
  search_query  = params[:search]
  archive_month = params[:month]

  if    category_slug
    @posts = BlogPost.published_in_category(category_slug)
  elsif search_query
    @posts = BlogPost.blog_search(search_query)
  elsif archive_month
    month = archive_month.split("-")[0].to_i
    year  = archive_month.split("-")[1].to_i
    @posts = BlogPost.published_in_month(month, year)
  else
    @posts = BlogPost.published
  end

  @posts = @posts.page params[:page]
end

#postObject



22
23
24
# File 'lib/generators/active_admin/blog/templates/controllers/blog_controller.rb', line 22

def post
  @post = BlogPost.find_by_permalink!(params[:slug])
end