summaryrefslogtreecommitdiff
path: root/app/controllers/occurrences_controller.rb
blob: 0f30ce38de8048670e2ea20f03b17393e09fbd3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class OccurrencesController < ApplicationController
  
  # Private
  
  before_action :login_required
  
  # GET /occurrences
  # GET /occurrences.xml
  def index
    @occurrences = Occurrence.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @occurrences }
    end
  end

  # GET /occurrences/1
  # GET /occurrences/1.xml
  def show
    @occurrence = Occurrence.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @occurrence }
    end
  end

  # GET /occurrences/new
  # GET /occurrences/new.xml
  def new
    @occurrence = Occurrence.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @occurrence }
    end
  end

  # GET /occurrences/1/edit
  def edit
    @occurrence = Occurrence.find(params[:id])
  end

  # POST /occurrences
  # POST /occurrences.xml
  def create
    @occurrence = Occurrence.new(occurrence_params)

    respond_to do |format|
      if @occurrence.save
        flash[:notice] = 'Occurrence was successfully created.'
        format.html { redirect_to(@occurrence) }
        format.xml  { render :xml => @occurrence, :status => :created, :location => @occurrence }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @occurrence.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /occurrences/1
  # PUT /occurrences/1.xml
  def update
    @occurrence = Occurrence.find(params[:id])

    respond_to do |format|
      if @occurrence.update(occurrence_params)
        flash[:notice] = 'Occurrence was successfully updated.'
        format.html { redirect_to(@occurrence) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @occurrence.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /occurrences/1
  # DELETE /occurrences/1.xml
  def destroy
    @occurrence = Occurrence.find(params[:id])
    @occurrence.destroy

    respond_to do |format|
      format.html { redirect_to(occurrences_url) }
      format.xml  { head :ok }
    end
  end

  private

    def occurrence_params
      params.require(:occurrence).permit(:start_time, :end_time, :node_id, :event_id)
    end

end