Class: BlogsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/blogs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject


2
3
4
# File 'app/controllers/blogs_controller.rb', line 2

def index
  @blogs = Blog.popular
end

#showObject


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/blogs_controller.rb', line 6

def show
  @blog = Blog.find_by!(slug: params[:slug])

  unless request.path == URI(blog_path(@blog.slug, format: params[:format])).path
    redirect_to blog_path(@blog.slug, format: params[:format])
    return
  end

  @posts = @blog.posts

  @posts = @posts.includes(:blog).order('created_at DESC').limit(12)
  @posts = @posts.older_than(Time.at(params[:before].to_f)) if params[:before].present?

  respond_to do |format|
    format.html
    format.atom
  end
end