@task.lecture = Lecture.find params[:lecture_id]
@apk = Apk.new params[:apk]
uploaded_file = params[:apkfile] && params[:apkfile][:file]
+ if uploaded_file.nil?
+ @noapk = I18n.t 'task.create.noapk'
+ end
+ @apk.task = @task
respond_to do |format|
format.html do
if teacher and @task.lecture.teacher.id == teacher.id
- if uploaded_file
- # TODO: check if the uploaded apk is correct
- if @apk.save
- @apk.store_file uploaded_file.tempfile
-
- @task.apks << @apk
- if @task.save
- redirect_to @task.lecture, :notice => I18n.t('task.create.success')
- else
- render :action => 'new'
- end
- else
- render :action => 'new'
- end
+ # TODO: check if the uploaded apk is correct
+ if !@noapk and @task.save and @apk.save
+ @apk.store_file uploaded_file.tempfile
+ redirect_to @task.lecture, :notice => I18n.t('task.create.success')
else
- @noapk = I18n.t('task.create.noapk')
+ if @task.persisted?
+ @task.destroy
+ end
render :action => 'new'
end
else
belongs_to :task
attr_accessible :name, :revision
+ validates_presence_of :task, :name, :revision
+
include JsonWithoutTimestamps
def as_json(options = {})
super options.merge({:except => [:task_id]})
has_many :apks, :order => 'revision DESC'
attr_accessible :name
+ validates_presence_of :lecture, :name
+
include JsonWithoutTimestamps
def as_json(options = {})
super options.merge({:methods => [:apk], :except => [:lecture_id]})