class Admin::DayoffsController < OrbitMemberController before_action :set_dayoff, only: [:show, :edit , :update, :destroy] include Admin::MemberlogsHelper layout "member_plugin" def index @dayoffs = Dayoff.all end def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @dayoff = Dayoff.new end def create # render :text =>"#{params[:dayoff]}" @dayoff = Dayoff.create(dayoff_params) redirect_to params[:referer_url] end def edit @dayoff = Dayoff.find(params[:id]) end def update @dayoff.update_attributes(dayoff_params) @dayoff.save redirect_to params[:referer_url] end def destroy dayoff = Dayoff.find(params[:id]) rescue nil if !dayoff.nil? dayoff.destroy end end def update_dayoff @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil @intro = MemberlogIntro.find_by(:member_profile_id=>@member.id) rescue nil @intro = @intro.nil? ? MemberlogIntro.new({:member_profile_id=>@member.id}) : @intro @intro.update_attributes(intro_params) @intro.save redirect_to URI.encode('/admin/members/'+@member.to_param+'/Memberog') end private def dayoff_params params.require(:dayoff).permit! end def set_dayoff path = request.path.split('/') if path.last.include? '-' uid = path[-1].split("-").last uid = uid.split("?").first else uid = path[-2].split("-").last uid = uid.split("?").first end @dayoff = Dayoff.find_by(:uid => uid) rescue Dayoff.find(params[:id]) end end