Sha256: 6ef77955d034f4582a29254ce75dd7d03ef0f58cc4e0bf714f4ef3c95bcc355f

Contents?: true

Size: 662 Bytes

Versions: 2

Compression:

Stored size: 662 Bytes

Contents

class Todos::CompletedController::Create < BaseAction
  def default_view_data
    super.merge({todo: todo})
  end

  def perform
    return build_view(Home::ShowRedirect) unless current_user
    return build_view(Todos::NotFoundView, todo_id: todo_id) unless todo
    return build_view(Defaults::ForbiddenView) unless current_ability.can?(:update, todo)

    todo.done = true

    if todo.save
      build_view(Todos::IndexRedirect)
    else
      build_view(Defaults::ServerErrorView, errors: ["Unable to mark todo completed"])
    end
  end

  private

  def todo
    @todo ||= Todo.where(id: todo_id).first
  end

  def todo_id
    params[:todo_id]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aldous-1.0.1 examples/basic_todo/app/controller_actions/todos/completed_controller/create.rb
aldous-1.0.0 examples/basic_todo/app/controller_actions/todos/completed_controller/create.rb