Sha256: 328ed2e542c95e897d14316273bfe818c92b83625b94348790e35bed42a09832

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

class Comments < Items
  # prepare_model Comment, finder: :by_slug!, only: %w(show edit update destroy)

  allow_get_for :show, :new, :edit

  def show
    require_permission :view, @model
  end

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

  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

  def edit
    require_permission :update_comment, @model
  end

  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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_kit-0.0.10 app/controllers/comments.rb