OSDN Git Service

Merge remote-tracking branch 'origin/ticket29809/register-tasks'
[sharp4k/CUTEn.git] / CutenServer / app / controllers / lectures_controller.rb
1 class LecturesController < ApplicationController
2   # GET /lectures
3   # GET /lectures.json
4   def index
5     if params[:ids] and params[:ids].is_a? Array
6       @lectures = Lecture.where :id => params[:ids]
7       render json: @lectures.as_json(:methods => [:tasks])
8     else
9       @lectures = Lecture.all
10       render json: @lectures
11     end
12   end
13
14   # GET /lectures/new
15   def new
16     if user_signed_in?
17       respond_to do |format|
18         format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
19       end
20     else
21       authenticate_teacher!
22       @lecture = Lecture.new
23       @lecture.teacher = current_teacher
24
25       respond_to do |format|
26         format.html # new.html.haml
27       end
28     end
29   end
30
31   # POST /lectures
32   def create
33     respond_to do |format|
34       if user_signed_in?
35         format.html { redirect_to root_path, :alert => I18n.t('teacher.not') }
36       else
37         authenticate_teacher!
38         @lecture = Lecture.new params[:lecture]
39         @lecture.teacher = current_teacher
40
41         if @lecture.save
42           format.html { redirect_to @lecture, :notice => I18n.t('lecture.created') }
43         else
44           format.html { render :action => 'new' }
45         end
46       end
47     end
48   end
49
50   # GET /lectures/1
51   # GET /lectures/1.json
52   def show
53     @lecture = Lecture.find(params[:id])
54
55     respond_to do |format|
56       format.html # show.html.haml
57       format.json { render :json => @lecture }
58     end
59   end
60 end