Class: CoursesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CoursesController
- Defined in:
- app/controllers/courses_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
post /courses.
-
#destroy ⇒ Object
delete /courses/:id.
-
#edit ⇒ Object
get /courses/:id/edit.
-
#index ⇒ Object
get /courses.
-
#new ⇒ Object
get /courses/new.
-
#show ⇒ Object
get /courses/:id.
-
#update ⇒ Object
patch /courses/:id.
Instance Method Details
#create ⇒ Object
post /courses
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/courses_controller.rb', line 19 def create @entity = Course.new(creation_parameters) if @entity.save next_page = admin_course_path(@entity.id) respond_to do |format| format.html { redirect_to next_page } format.json { render json: { links: { self: next_page } } } format.js { render js: "document.location.href = '#{next_page}'" } end else render :new, status: :bad_request end end |
#destroy ⇒ Object
delete /courses/:id
60 61 62 63 64 65 |
# File 'app/controllers/courses_controller.rb', line 60 def destroy if @entity.destroy #@entity.update(deleted: true) flash[:notice] = t('courses.destroy.success') end redirect_to admin_courses_path end |
#edit ⇒ Object
get /courses/:id/edit
42 43 |
# File 'app/controllers/courses_controller.rb', line 42 def edit end |
#index ⇒ Object
get /courses
9 10 11 |
# File 'app/controllers/courses_controller.rb', line 9 def index @collection = Course.page_for_visitors(current_page) end |
#new ⇒ Object
get /courses/new
14 15 16 |
# File 'app/controllers/courses_controller.rb', line 14 def new @entity = Course.new end |
#show ⇒ Object
get /courses/:id
34 35 36 37 38 39 |
# File 'app/controllers/courses_controller.rb', line 34 def show @entity = Course.find_by(id: params[:id], visible: true, deleted: false) if @entity.nil? handle_http_404("Cannot find non-deleted course #{params[:id]}") end end |
#update ⇒ Object
patch /courses/:id
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/courses_controller.rb', line 46 def update if @entity.update(entity_parameters) next_page = admin_course_path(@entity.id) respond_to do |format| format.html { redirect_to next_page } format.json { render json: { links: { self: next_page } } } format.js { render js: "document.location.href = '#{next_page}'" } end else render :edit, status: :bad_request end end |