def index
if params[:ids] and params[:ids].is_a? Array
@lectures = Lecture.where :id => params[:ids]
- render json: @lectures.as_json(:methods => [:tasks])
+ respond_to do |format|
+ format.json { render json: @lectures.as_json(:methods => [:tasks]) }
+ end
else
@lectures = Lecture.all
- render json: @lectures
+ respond_to do |format|
+ format.html
+ format.json { render json: @lectures }
+ end
end
end
# GET /lectures/new
def new
- authenticate_user!
- @lecture = Lecture.new
- @lecture.teacher = current_user.teacher
+ if user_signed_in?
+ respond_to do |format|
+ format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
+ end
+ else
+ authenticate_teacher!
+ @lecture = Lecture.new
+ @lecture.teacher = current_teacher
- respond_to do |format|
- if @lecture.teacher
+ respond_to do |format|
format.html # new.html.haml
- else
- format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
end
end
end
# POST /lectures
def create
- authenticate_user!
- @lecture = Lecture.new params[:lecture]
- @lecture.teacher = current_user.teacher
-
respond_to do |format|
- if @lecture.teacher
+ if user_signed_in?
+ format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
+ else
+ authenticate_teacher!
+ @lecture = Lecture.new params[:lecture]
+ @lecture.teacher = current_teacher
+
if @lecture.save
- format.html { redirect_to @lecture, :notice => I18n.t('lectures.created') }
+ format.html { redirect_to @lecture, :notice => I18n.t('lecture.created') }
else
format.html { render :action => 'new' }
end
- else
- format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
end
end
end
format.json { render :json => @lecture }
end
end
-
- def tasks
- @lecture = Lecture.find(params[:id])
- render :json => @lecture.tasks
- end
end