こんにちは私は以下を達成するためのより簡単な/論理的な方法があるかどうか疑問に思っています
def index
@date = params[:month] ? Date.parse(params[:month]) : Date.today
@schedule = Schedule.new
@players = User.where(:team_id => current_user[:team_id]).all
if current_user.admin?
@schedules = Schedule.all
elsif current_user.manager?
@schedules = Schedule.find_all_by_team_id(current_user[:team_id])
if @schedules.count < 1
redirect_to(root_path, :status => 301, :alert => "This team has no upcoming events<br/> You should add your next event, and TeamMNGT will take care of everything else!".html_safe)
return
end
elsif current_user.team_id?
@schedules = Schedule.find_all_by_team_id(current_user[:team_id])
elsif @schedules.count < 1 and current_user.team_id?
redirect_to(root_path, :status => 301, :alert => "You don't have any upcoming events.<br/> Your team manager has not added any upcoming events for #{@team.name}".html_safe)
return
else
redirect_to root_path, :status => 301, :alert => "Please contact your club administrator to be assigned to a team."
return
end
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @schedules }
end
終わり