Class: Course::Achievement::AchievementsController

Inherits:
Controller show all
Defined in:
app/controllers/course/achievement/achievements_controller.rb

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#createObject

:nodoc:


12
13
14
15
16
17
18
# File 'app/controllers/course/achievement/achievements_controller.rb', line 12

def create #:nodoc:
  if @achievement.save
    render json: { id: @achievement.id }, status: :ok
  else
    render json: { errors: @achievement.errors }, status: :bad_request
  end
end

#destroyObject

:nodoc:


40
41
42
43
44
45
46
47
48
# File 'app/controllers/course/achievement/achievements_controller.rb', line 40

def destroy #:nodoc:
  if @achievement.destroy
    redirect_to course_achievements_path(current_course),
                success: t('.success', title: @achievement.title)
  else
    redirect_to course_achievements_path,
                danger: t('.failure', error: @achievement.errors.full_messages.to_sentence)
  end
end

#editObject

:nodoc:


20
21
# File 'app/controllers/course/achievement/achievements_controller.rb', line 20

def edit #:nodoc:
end

#indexObject

:nodoc:


5
6
7
# File 'app/controllers/course/achievement/achievements_controller.rb', line 5

def index #:nodoc:
  @achievements = @achievements.includes(:conditions)
end

#reorderObject


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/course/achievement/achievements_controller.rb', line 50

def reorder
  unless valid_ordering?(achievement_order_params)
    raise ArgumentError, 'Invalid ordering for achievements'
  end

  Course::Achievement.transaction do
    achievement_order_params.each_with_index do |id, index|
      achievements_hash[id].update_attribute(:weight, index)
    end
  end

  head :ok
end

#showObject

:nodoc:


9
10
# File 'app/controllers/course/achievement/achievements_controller.rb', line 9

def show #:nodoc:
end

#updateObject

:nodoc:


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/course/achievement/achievements_controller.rb', line 23

def update #:nodoc:
  if @achievement.update_attributes(achievement_params)
    respond_to do |format|
      format.html do
        redirect_to course_achievement_path(current_course, @achievement.id),
                    success: t('.success')
      end
      format.json { head :ok }
    end
  else
    respond_to do |format|
      format.html { render 'edit' }
      format.json { render json: { errors: @achievement.errors }, status: :bad_request }
    end
  end
end