1 class TasksController < ApplicationController
5 @task = Task.find(params[:id])
10 # GET /lectures/:lecture_id/tasks/new
13 teacher = current_user.teacher
16 @task.lecture = Lecture.find params[:lecture_id]
19 respond_to do |format|
20 if teacher and @task.lecture.teacher.id == teacher.id
21 format.html # new.html.haml
23 format.html { redirect_to @task.lecture, :alert => I18n.t('task.create.unauthorized') }
28 # POST /lectures/:lecture_id/tasks
31 teacher = current_user.teacher
32 @task = Task.new params[:task]
33 @task.lecture = Lecture.find params[:lecture_id]
34 @apk = Apk.new params[:apk]
35 uploaded_file = params[:apkfile] && params[:apkfile][:file]
37 respond_to do |format|
39 if teacher and @task.lecture.teacher.id == teacher.id
41 # TODO: check if the uploaded apk is correct
43 @apk.store_file uploaded_file.tempfile
47 redirect_to @task.lecture, :notice => I18n.t('task.create.success')
49 render :action => 'new'
52 render :action => 'new'
55 @noapk = I18n.t('task.create.noapk')
56 render :action => 'new'
59 redirect_to @task.lecture, :alert => I18n.t('task.create.unauthorized')