Class: FeatureBox::CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #pages_helper, #retrieve_vars

Methods included from Helpers

define_helpers, included

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/feature_box/comments_controller.rb', line 7

def create
  suggestion =Suggestion.find(params["suggestion_id"])
  @comment.text = params["comment"]["text"]
  @comment.user = current_user
  @comment.suggestion = suggestion
    if @comment.save
      redirect_to suggestion, notice: 'Comment was successfully added.'       
    else
      redirect_to suggestion, :flash => { 
        #TODO: it can be anything, not only empty comment
        :error => 'Comment cannot be empty'
      }
    end
end

#destroyObject



38
39
40
41
# File 'app/controllers/feature_box/comments_controller.rb', line 38

def destroy
  @comment.destroy
  redirect_to @comment.suggestion, notice: 'Comment was successfully deleted.'     
end

#editObject



22
23
# File 'app/controllers/feature_box/comments_controller.rb', line 22

def edit
end

#showObject



25
26
27
# File 'app/controllers/feature_box/comments_controller.rb', line 25

def show
  redirect_to @comment.suggestion
end

#updateObject



29
30
31
32
33
34
35
36
# File 'app/controllers/feature_box/comments_controller.rb', line 29

def update
  @comment.text = params[:comment][:text]
  if @comment.save
    redirect_to @comment.suggestion, notice: 'Comment was successfully updated.' 
  else
    render action: "edit" 
  end
end