OSDN Git Service

Follow the model's change
[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     authenticate_teacher!
17     @lecture = Lecture.new
18     @lecture.teacher = current_teacher
19
20     respond_to do |format|
21       format.html # new.html.haml
22     end
23   end
24
25   # POST /lectures
26   def create
27     authenticate_teacher!
28     @lecture = Lecture.new params[:lecture]
29     @lecture.teacher = current_teacher
30
31     respond_to do |format|
32       if @lecture.save
33         format.html { redirect_to @lecture, :notice => I18n.t('lecture.created') }
34       else
35         format.html { render :action => 'new' }
36       end
37     end
38   end
39
40   # GET /lectures/1
41   # GET /lectures/1.json
42   def show
43     @lecture = Lecture.find(params[:id])
44
45     respond_to do |format|
46       format.html # show.html.haml
47       format.json { render :json => @lecture }
48     end
49   end
50 end