diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index feeb3c324..3e5e131c8 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -1,5 +1,5 @@ class PollController < ApplicationController - before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll] + before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer] before_filter :find_container, :only => [:new,:create, :index] before_filter :is_member_of_course, :only => [:index,:show] before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy] @@ -19,10 +19,16 @@ class PollController < ApplicationController def show @poll = Poll.find params[:id] - poll_questions = @poll.poll_questions - @poll_questions = paginateHelper poll_questions,3 #分页 - respond_to do |format| - format.html {render :layout => 'base_courses'} + #已提交问卷的用户不能再访问该界面 + if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?) + render_403 + else + @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin? + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions,3 #分页 + respond_to do |format| + format.html {render :layout => 'base_courses'} + end end end @@ -141,6 +147,10 @@ class PollController < ApplicationController #提交答案 def commit_answer pq = PollQuestion.find(params[:poll_question_id]) + if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?) + render :text => 'failure' + return + end if pq.question_type == 1 #单选题 pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id) @@ -188,15 +198,8 @@ class PollController < ApplicationController render :text => "failure" end else - + render :text => "failure" end - - - #respond_to do |format| - # format.js - # format.json - #end - end #提交问卷 diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 1c9ecd40f..7816d8e37 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -37,4 +37,14 @@ module PollHelper pv.vote_text end end + + #判断用户是否已经提交了问卷 + def has_commit_poll?(poll_id,user_id) + pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id) + if pu.nil? + false + else + true + end + end end \ No newline at end of file diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb index 9d0bd5549..e45bdfabb 100644 --- a/app/views/poll/index.html.erb +++ b/app/views/poll/index.html.erb @@ -13,7 +13,11 @@ <% @polls.each do |poll|%>