Class: DataMigration::MigrationStepsController

Inherits:
ApplicationController show all
Includes:
PunditAuthorization
Defined in:
app/controllers/data_migration/migration_steps_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 23

def create
  @migration_step = @migration_plan.migration_steps.new(migration_step_params)
  authorize @migration_step

  # Validate JSON fields before saving
  validation_errors = validate_json_fields(@migration_step)
  if validation_errors.any?
    validation_errors.each { |error| @migration_step.errors.add(:base, error) }
    render :new, status: :unprocessable_entity
    return
  end

  if @migration_step.save
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
                notice: 'Migration step was successfully created.'
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



69
70
71
72
73
74
75
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 69

def destroy
  authorize @migration_step

  @migration_step.destroy
  redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
              notice: 'Migration step was successfully destroyed.'
end

#editObject



43
44
45
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 43

def edit
  authorize @migration_step
end

#indexObject



10
11
12
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 10

def index
  @migration_steps = policy_scope(MigrationStep).where(migration_plan_id: params[:migration_plan_id]).order(:sequence)
end

#newObject



18
19
20
21
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 18

def new
  @migration_step = @migration_plan.migration_steps.new
  authorize @migration_step
end

#showObject



14
15
16
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 14

def show
  authorize @migration_step
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/data_migration/migration_steps_controller.rb', line 47

def update
  authorize @migration_step

  # Assign attributes first
  @migration_step.assign_attributes(migration_step_params)

  # Validate JSON fields before saving
  validation_errors = validate_json_fields(@migration_step)
  if validation_errors.any?
    validation_errors.each { |error| @migration_step.errors.add(:base, error) }
    render :edit, status: :unprocessable_entity
    return
  end

  if @migration_step.save
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
                notice: 'Migration step was successfully updated.'
  else
    render :edit, status: :unprocessable_entity
  end
end