#1377 当指定ID不存在时,给出该课程不存在的提示
This commit is contained in:
parent
71cc4c3860
commit
90d4140a25
|
@ -25,25 +25,28 @@ class CoursesController < ApplicationController
|
||||||
|
|
||||||
def join
|
def join
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
course = Course.find(params[:object_id])
|
course = Course.find_by_id params[:object_id]
|
||||||
unless User.current.member_of_course? course
|
if course
|
||||||
if params[:course_password] == course.password
|
@state = 4
|
||||||
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
|
else
|
||||||
@state = 3
|
unless User.current.member_of_course? course
|
||||||
|
if params[:course_password] == course.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 = 3
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@state = 4
|
@state = 5
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
|
||||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
alert("您已经加入了课程");
|
alert("您已经加入了课程");
|
||||||
<% elsif @state == 4 %>
|
<% elsif @state == 4 %>
|
||||||
alert("您已经的课程不存在");
|
alert("您已经的课程不存在");
|
||||||
<% elsif @state == 4 %>
|
<% elsif @state == 5 %>
|
||||||
alert("您还未登录");
|
alert("您还未登录");
|
||||||
<% else %>
|
<% else %>
|
||||||
alert("未知错误,请稍后再试");
|
alert("未知错误,请稍后再试");
|
||||||
|
|
Loading…
Reference in New Issue