1
0
Fork 0
MSU-Course-Alerter/app/controllers/alerts_controller.rb

86 lines
1.9 KiB
Ruby
Raw Normal View History

2013-04-02 02:43:01 -04:00
class AlertsController < ApplicationController
2013-04-06 01:05:36 -04:00
before_filter :authenticate_user!
2013-04-02 02:43:01 -04:00
# GET /alerts
# GET /alerts.json
def index
@alerts = Alert.user_alerts(current_user.id)
2013-04-02 02:43:01 -04:00
respond_to do |format|
format.html # index.html.erb
format.json { render json: @alerts }
end
end
# GET /alerts/1
# GET /alerts/1.json
def show
@alert = Alert.find(params[:id])
respond_to do |format|
format.html # show.html.erb
2013-04-03 19:35:03 -04:00
format.xml # show.xml.builder
2013-04-02 02:43:01 -04:00
format.json { render json: @alert }
end
end
# GET /alerts/new
# GET /alerts/new.json
def new
@alert = Alert.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @alert }
end
end
# GET /alerts/1/edit
def edit
@alert = Alert.find(params[:id])
end
# POST /alerts
# POST /alerts.json
def create
@alert = Alert.new(params[:alert])
respond_to do |format|
if @alert.save
format.html { redirect_to @alert, notice: 'Alert was successfully created.' }
format.json { render json: @alert, status: :created, location: @alert }
else
format.html { render action: "new" }
format.json { render json: @alert.errors, status: :unprocessable_entity }
end
end
end
# PUT /alerts/1
# PUT /alerts/1.json
def update
@alert = Alert.find(params[:id])
respond_to do |format|
if @alert.update_attributes(params[:alert])
format.html { redirect_to @alert, notice: 'Alert was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @alert.errors, status: :unprocessable_entity }
end
end
end
# DELETE /alerts/1
# DELETE /alerts/1.json
def destroy
@alert = Alert.find(params[:id])
@alert.destroy
respond_to do |format|
format.html { redirect_to alerts_url }
format.json { head :no_content }
end
end
end