Class: PostsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

caches_page_with_cache_marker, #raise_not_found!

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/posts_controller.rb', line 9

def index
  @posts = Post.filter(params).per(params[:per])

  if params[:q].blank? && params[:tag].present? && @posts.empty?
    raise ActiveRecord::RecordNotFound, 'Posts not found'
  end

  respond_with @posts
end

#searchObject



19
20
21
22
23
24
# File 'app/controllers/posts_controller.rb', line 19

def search
  params[:per] = 10 if params[:per].blank? || params[:per].to_i < 1

  @posts = Post.filter(params).per(params[:per])
  render :index
end

#showObject

Raises:

  • (ActiveRecord::RecordNotFound)


26
27
28
29
30
31
32
33
34
# File 'app/controllers/posts_controller.rb', line 26

def show
  @post = Post.past.find_by(slug: params[:id])
  raise ActiveRecord::RecordNotFound, "Post #{params[:id]} not found" unless @post

  # Seo meta tags
  @meta_record = @post

  respond_with @post
end