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

61 lines
1.3 KiB
Ruby
Raw Normal View History

2014-11-07 08:44:11 +00:00
# encoding: utf-8
class Admin::NewsAdminsController < OrbitAdminController
def initialize
super
2014-11-12 03:33:47 +00:00
@app_title = 'news'
2014-11-07 08:44:11 +00:00
end
def index
@unit_table_fields = ['news.unit','news.department']
@unit = Unit.new
2014-12-08 07:19:37 +00:00
sort = (!params[:sort].blank? ? {params[:sort].to_sym=>params[:order]} : {:id=>"asc"})
2014-11-07 08:44:11 +00:00
@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']
2014-12-08 07:19:37 +00:00
sort = (!params[:sort].blank? ? {params[:sort].to_sym=>params[:order]} : {:id=>"asc"})
2014-11-07 08:44:11 +00:00
@units = Unit.order_by(sort)
@url = admin_news_admin_path(@unit)
end
def update
2015-09-24 06:41:47 +00:00
@unit = Unit.find_by(:uid => params[:id].split("-").last) rescue nil
2015-09-24 07:06:55 +00:00
@unit.update_attributes(unit_params) #if !@unit.nil?
2014-11-07 08:44:11 +00:00
redirect_to admin_news_admins_path
end
def destroy
unit = Unit.find(params[:id])
unit.destroy
redirect_to admin_news_admins_path
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
2015-09-24 07:23:49 +00:00
private
def unit_params
params.require(:unit).permit!
end
2014-11-07 08:44:11 +00:00
end