Show More
Commit Description:
add submissions to users
Commit Description:
add submissions to users
References:
File last commit:
Show/Diff file:
Action:
app/controllers/announcements_controller.rb
| 116 lines
| 3.2 KiB
| text/x-ruby
| RubyLexer
|
|
|
r97 | class AnnouncementsController < ApplicationController | ||
|
|
r104 | before_filter :admin_authorization | ||
|
|
r97 | |||
| in_place_edit_for :announcement, :published | ||||
| # GET /announcements | ||||
| # GET /announcements.xml | ||||
| def index | ||||
| r619 | @announcements = Announcement.order(created_at: :desc) | |||
|
|
r97 | |||
| respond_to do |format| | ||||
| format.html # index.html.erb | ||||
| format.xml { render :xml => @announcements } | ||||
| end | ||||
| end | ||||
| # GET /announcements/1 | ||||
| # GET /announcements/1.xml | ||||
| def show | ||||
| @announcement = Announcement.find(params[:id]) | ||||
| respond_to do |format| | ||||
| format.html # show.html.erb | ||||
| format.xml { render :xml => @announcement } | ||||
| end | ||||
| end | ||||
| # GET /announcements/new | ||||
| # GET /announcements/new.xml | ||||
| def new | ||||
| @announcement = Announcement.new | ||||
| respond_to do |format| | ||||
| format.html # new.html.erb | ||||
| format.xml { render :xml => @announcement } | ||||
| end | ||||
| end | ||||
| # GET /announcements/1/edit | ||||
| def edit | ||||
| @announcement = Announcement.find(params[:id]) | ||||
| end | ||||
| # POST /announcements | ||||
| # POST /announcements.xml | ||||
| def create | ||||
| r637 | @announcement = Announcement.new(announcement_params) | |||
|
|
r97 | |||
| respond_to do |format| | ||||
| if @announcement.save | ||||
| flash[:notice] = 'Announcement was successfully created.' | ||||
| format.html { redirect_to(@announcement) } | ||||
| format.xml { render :xml => @announcement, :status => :created, :location => @announcement } | ||||
| else | ||||
| format.html { render :action => "new" } | ||||
| format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } | ||||
| end | ||||
| end | ||||
| end | ||||
| # PUT /announcements/1 | ||||
| # PUT /announcements/1.xml | ||||
| def update | ||||
| @announcement = Announcement.find(params[:id]) | ||||
| respond_to do |format| | ||||
| r617 | if @announcement.update_attributes(announcement_params) | |||
|
|
r97 | flash[:notice] = 'Announcement was successfully updated.' | ||
| format.html { redirect_to(@announcement) } | ||||
| r556 | format.js {} | |||
|
|
r97 | format.xml { head :ok } | ||
| else | ||||
| format.html { render :action => "edit" } | ||||
| r556 | format.js {} | |||
|
|
r97 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } | ||
| end | ||||
| end | ||||
| end | ||||
| r556 | def toggle | |||
| @announcement = Announcement.find(params[:id]) | ||||
| r557 | @announcement.update_attributes( published: !@announcement.published? ) | |||
| r556 | respond_to do |format| | |||
| r562 | format.js { render partial: 'toggle_button', | |||
| locals: {button_id: "#announcement_toggle_#{@announcement.id}",button_on: @announcement.published? } } | ||||
| r556 | end | |||
| end | ||||
| r567 | def toggle_front | |||
| @announcement = Announcement.find(params[:id]) | ||||
| @announcement.update_attributes( frontpage: !@announcement.frontpage? ) | ||||
| respond_to do |format| | ||||
| format.js { render partial: 'toggle_button', | ||||
| locals: {button_id: "#announcement_toggle_front_#{@announcement.id}",button_on: @announcement.frontpage? } } | ||||
| end | ||||
| end | ||||
|
|
r97 | # DELETE /announcements/1 | ||
| # DELETE /announcements/1.xml | ||||
| def destroy | ||||
| @announcement = Announcement.find(params[:id]) | ||||
| @announcement.destroy | ||||
| respond_to do |format| | ||||
| format.html { redirect_to(announcements_url) } | ||||
| format.xml { head :ok } | ||||
| end | ||||
| end | ||||
| r617 | ||||
| private | ||||
| def announcement_params | ||||
| r642 | params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title) | |||
| r617 | end | |||
|
|
r97 | end | ||
