personal-course/app/controllers/admin/course_categories_controlle...

47 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2015-12-29 11:35:44 +00:00
class Admin::CourseCategoriesController < OrbitMemberController
def index
end
def new
@course_category = CourseCategory.new
@url = admin_course_categories_path
end
def edit
@course_category = CourseCategory.find(params[:id])
@url = admin_course_category_path(@course_category)
end
def create
course_category = CourseCategory.create(course_category_params)
@course_categories = CourseCategory.all.order_by(:sort_position => "asc")
end
def update
course_category = CourseCategory.find(params[:id]) rescue nil
course_category.update_attributes(course_category_params) if !course_category.nil?
@course_categories = CourseCategory.all.order_by(:sort_position => "asc")
end
def destroy
course_category = CourseCategory.find(params[:id]) rescue nil
course_category.destroy if !course_category.nil?
@course_categories = CourseCategory.all.order_by(:sort_position => "asc")
end
def update_order
orders = params["order"]
CourseCategory.each do |cc|
cc.sort_position = orders["#{cc.id}"]
cc.save
end
render :json => {"success" => true}.to_json
end
private
def course_category_params
params.require(:course_category).permit!
end
end