#1377 当指定ID不存在时,给出该课程不存在的提示

This commit is contained in:
sw 2014-10-20 17:23:38 +08:00
parent 71cc4c3860
commit 90d4140a25
2 changed files with 18 additions and 15 deletions

View File

@ -25,25 +25,28 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
course = Course.find(params[:object_id])
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
course = Course.find_by_id params[:object_id]
if course
@state = 4
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
else
@state = 4
@state = 5
end
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]} }
end
rescue Exception => e

View File

@ -12,7 +12,7 @@
alert("您已经加入了课程");
<% elsif @state == 4 %>
alert("您已经的课程不存在");
<% elsif @state == 4 %>
<% elsif @state == 5 %>
alert("您还未登录");
<% else %>
alert("未知错误,请稍后再试");