过滤器过滤加入课程的行为,不再进行n多判断

This commit is contained in:
yanxd 2014-03-19 15:50:02 +08:00
parent e1ddb3b0f6
commit f9e9404471
1 changed files with 16 additions and 9 deletions

View File

@ -7,20 +7,16 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
course = Project.find(params[:object_id])
if ( !course_endTime_timeout?(course) )
course_prefs = Course.find_by_extra(course.identifier)
if params[:course_password] == course_prefs.password
course_prefs = Course.find_by_extra(course.identifier)
if params[:course_password] == course_prefs.password
members = []
members << Member.new(:role_ids => [10], :user_id => User.current.id)
course.members << members
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
@state = 0
else
@state = 1
end
else
@state = 2
@state = 1
end
end
respond_to do |format|
@ -49,7 +45,18 @@ class CoursesController < ApplicationController
private
def allow_join
course_endTime_timeout? Project.find(params[:object_id])
if course_endTime_timeout? Project.find(params[:object_id])
respond_to do |format|
format.js{
@state = 2
render :partial => 'set_join',
:locals => {:user => User.current,
:course => Project.find(params[:object_id]),
:object_id => params[:object_id]
}
}
end
end
end
end