Class: Kwipper::PostsController

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

Constant Summary

Constants inherited from Controller

Controller::ROUTES

Constants included from RendersViews

RendersViews::VIEWS_PATH, RendersViews::VIEW_EXT

Instance Attribute Summary

Attributes inherited from Controller

#action, #app, #request, #response

Instance Method Summary collapse

Methods inherited from Controller

add_routes, #home, #initialize, #process

Methods included from RendersViews

#render

Constructor Details

This class inherits a constructor from Kwipper::Controller

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/posts_controller.rb', line 27

def create
  require_login!
  post = Post.new params.merge({
    'user_id'    => current_user.id,
    'created_at' => Time.now.httpdate
  })

  if post.save
    redirect '/kwips'
  else
    redirect '/kwips/new', :bad_request
  end
end

#newObject



22
23
24
25
# File 'app/controllers/posts_controller.rb', line 22

def new
  require_login!
  render :new_post
end

#postsObject



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

def posts
  @paginator = Paginator.new Post, page: params['page'], per: 10, path: '/kwips'
  @posts = @paginator.get "SELECT * FROM posts ORDER BY created_at DESC"
  render :posts
end

#showObject



16
17
18
19
20
# File 'app/controllers/posts_controller.rb', line 16

def show
  @post = Post.find params['id']
  @comments = @post.comments
  render :show_post
end