Render errors in JSON in the schedule correctly

This commit is contained in:
Ana 2016-08-09 14:55:39 +02:00
parent e8261d41bc
commit a1c7f67735
5 changed files with 32 additions and 37 deletions

View file

@ -4,25 +4,25 @@ module Admin
def create
if @event_schedule.save
render json: { 'status' => 'ok', event_schedule_id: @event_schedule.id }
render json: { event_schedule_id: @event_schedule.id }
else
render json: { 'status' => "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
end
end
def update
if @event_schedule.update(event_schedule_params)
render json: { 'status' => 'ok', event_schedule_id: @event_schedule.id }
render json: { event_schedule_id: @event_schedule.id }
else
render json: { 'status' => "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
end
end
def destroy
if @event_schedule.destroy
render json: { 'status' => 'ok' }
render json: {}
else
render json: { 'status' => "The event couldn't be unscheduled. #{@event_schedule.errors.full_messages.join('. ')}" }
render json: { errors: "The event couldn't be unscheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
end
end

View file

@ -20,7 +20,7 @@ module Admin
redirect_to admin_conference_program_path(@conference.short_title),
notice: 'The program was successfully updated.'
end
format.js { render json: { 'status' => 'ok' } }
format.js { render json: {} }
end
else
respond_to do |format|
@ -28,7 +28,7 @@ module Admin
flash[:error] = "Updating program failed. #{@program.errors.to_a.join('. ')}."
render :new
end
format.js { render json: { 'status' => "The selected schedule couldn't been updated #{@program.errors.to_a.join('. ')}" } }
format.js { render json: { errors: "The selected schedule couldn't been updated #{@program.errors.to_a.join('. ')}" }, status: 422 }
end
end
end