Class: Kwipper::CommentsController

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

Constant Summary

Constants inherited from Controller

Kwipper::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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/comments_controller.rb', line 14

def create
  require_login!

  post = Post.find params['id']
  comment = Comment.new({
    'user_id'    => current_user.id,
    'post_id'    => post.id,
    'created_at' => Time.now.httpdate,
    'content'    => params['content']
  })

  if comment.save
    redirect "/kwips/show?id=#{post.id}"
  else
    redirect "/kwips/comments/new?id=#{post.id}", :bad_request
  end
end

#newObject



8
9
10
11
12
# File 'app/controllers/comments_controller.rb', line 8

def new
  require_login!
  @post = Post.find params['id']
  render :new_comment
end