nccu-news/app/controllers/admin/news_admins_controller.rb

57 lines
1.1 KiB
Ruby
Raw Normal View History

2014-11-07 08:44:11 +00:00
# encoding: utf-8
class Admin::NewsAdminsController < OrbitAdminController
def initialize
super
@app_title = 'news_admin'
end
def index
@unit_table_fields = ['news.unit','news.department']
@unit = Unit.new
@units = Unit.order_by(sort)
end
def create
unit = Unit.new(unit_params)
unit.save
redirect_to admin_news_admins_path
end
def edit
@unit = Unit.find(params[:id])
@unit_table_fields = ['news.unit','news.department']
@units = Unit.order_by(sort)
@url = admin_news_admin_path(@unit)
end
def update
@unit = Unit.find(params[:id])
@unit.update_attributes(unit_params)
redirect_to admin_news_admins_path
end
def destroy
unit = Unit.find(params[:id])
unit.destroy
redirect_to admin_news_admins_path
end
def unit_params
params.require(:unit).permit!
end
def get_departments
unit = Unit.find(Sanitize.clean(params[:unit]))
departments = unit.departments.collect do |d|
{
"name" => d.name,
"id" => d.id.to_s
}
end
render :json => {"departments" => departments}.to_json
end
end