seminar2/app/controllers/admin/seminar_item_contents_contr...

71 lines
1.9 KiB
Ruby

# encoding: utf-8
class Admin::SeminarItemContentsController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def initialize
super
@app_title = "seminar"
end
def index
@seminar_item_contents = SeminarItemContent.where(:seminar_main_id => params[:seminar_main_id]).page(params[:page]).per(10)
@seminar = SeminarMain.find(params[:seminar_main_id])
@seminar_items = SeminarItem.where(:_id.nin=> SeminarItemContent.where(:seminar_main_id => params[:seminar_main_id]).collect{|t| t.seminar_item_id} ).collect{|a| [a.title,a.id]}
end
def new
@contents = SeminarItemContent.where(:seminar_main_id => params[:seminar_main_id]).collect{|t| t.seminar_item_id}
@seminar_item_content = SeminarItemContent.new
@seminar_items = SeminarItem.where(:_id.nin=> @contents).collect{|a| [a.title,a.id]}
end
def create
seminar_item_content = SeminarItemContent.new(seminar_item_content_params)
seminar_item_content.create_user_id = current_user.id
seminar_item_content.update_user_id = current_user.id
seminar_item_content.save
redirect_to params['referer_url']+"?seminar_main_id="+seminar_item_content.seminar_main_id
end
def edit
@seminar_item_content = SeminarItemContent.find(params[:id])
@seminar = SeminarMain.find(@seminar_item_content.seminar_main_id)
end
def update
@seminar_item_content = SeminarItemContent.find(params[:id])
@seminar_item_content.update_attributes(seminar_item_content_params)
redirect_to "/admin/seminar_item_contents?seminar_main_id="+@seminar_item_content.seminar_main_id
end
def destroy
@seminar_item_content = SeminarItemContent.find(params[:id])
@seminar_item_content.destroy
redirect_to "/admin/seminar_item_contents?seminar_main_id="+@seminar_item_content.seminar_main_id
end
private
def seminar_item_content_params
params.require(:seminar_item_content).permit!
end
end