Class: Comments

Inherits:
Items
  • Object
show all
Defined in:
app/controllers/comments.rb

Instance Method Summary collapse

Methods inherited from Items

#all, #collaborators, #layout, model_class, #model_class, #redirect, #viewers

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/comments.rb', line 16

def create
  require_permission :create_comment
  @item = Models::Item.by_param! params.item_id
  @model = Models::Comment.new params.model
  @model.item = @item
  @model.owner = Models::User.current
  if @model.save
    flash.info = t :comment_created
    # render action: :new
  else
    render action: :new
  end
end

#destroyObject



44
45
46
47
48
# File 'app/controllers/comments.rb', line 44

def destroy
  require_permission :destroy_comment, @model
  @model.destroy
  flash.info = t :comment_destroyed
end

#editObject



30
31
32
# File 'app/controllers/comments.rb', line 30

def edit
  require_permission :update_comment, @model
end

#newObject



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

def new
  require_permission :create_comment
  params.item_id.must_not_be.nil
  @model = Models::Comment.new
end

#showObject



6
7
8
# File 'app/controllers/comments.rb', line 6

def show
  require_permission :view, @model
end

#updateObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/comments.rb', line 34

def update
  require_permission :update_comment, @model
  if @model.set(params.model).save
    flash.info = t :comment_updated
    # render action: :update
  else
    render action: :edit
  end
end