重复提交问题

This commit is contained in:
wanglinchun 2014-01-17 16:42:31 +08:00
parent b2bdf0c640
commit 42a1a9e0b9
5 changed files with 47 additions and 19 deletions

View File

@ -17,6 +17,7 @@ class BidsController < ApplicationController
helper :watchers
helper :attachments
include AttachmentsHelper
include ApplicationHelper
helper :projects
helper :words
def index
@ -723,24 +724,33 @@ class BidsController < ApplicationController
if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
@homework = HomeworkAttach.new
@homework.safe_attributes = params[:homeworkattach]
@homework.bid_id = @bid.id
@homework.user_id = User.current.id
@homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework)
if @homework.save
@homework_flag = l(:label_bidding_homework_succeed)
if hadcommittedhomework(User.current.id, @bid.id) == true
@homework_flag = l(:label_bidding_homework_committed)
else
@homework_flag = l(:label_bidding_homework_failed)
end
if @homework.attachments.empty?
@homework.delete
flash[:error] = l(:no_attachmens_allowed)
@homework_flag = l(:no_attachmens_allowed)
# else
end
@homework = HomeworkAttach.new
@homework.safe_attributes = params[:homeworkattach]
@homework.bid_id = @bid.id
@homework.user_id = User.current.id
@homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework)
if @homework.save
@homework_flag = l(:label_bidding_homework_succeed)
else
@homework_flag = l(:label_bidding_homework_failed)
end
if @homework.attachments.empty?
@homework.delete
#flash[:error] = l(:no_attachmens_allowed)
@homework_flag = l(:no_attachmens_allowed)
# else
end
end
end
@homework_list = @bid.homeworks
respond_to do |format|
format.html{

View File

@ -1489,4 +1489,14 @@ module ApplicationHelper
obj2 = obj1
end
end
def hadcommittedhomework(cur,curb)
@attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})")
@attaches.each do |attach|
if attach.user_id == cur
return true
end
end
end
end

View File

@ -69,5 +69,14 @@ module AttachmentsHelper
def deletable? container, user=User.current
User.current.logged? && (container.author == user || user.admin?)
end
def hadcommittedhomework(cur,curb)
@attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})")
@attaches.each do |attach|
if attach.user_id == cur
retrun true
end
end
end
end

View File

@ -9,9 +9,7 @@
<%= render :partial => 'attachments/form' %>
</p>
</fieldset>
<%= submit_tag l(:button_create),
:onclick => "return true;"
%>
<%= submit_tag l(:button_create), :onclick => "return true" %>
<% end %>
<script type="text/javascript">
function j_submit () {

View File

@ -1338,6 +1338,7 @@ zh:
label_bidding_contest_succeed: 竞赛提交成功 #added by bai
label_bidding_homework_succeed: 作业提交成功 #added by bai
label_bidding_homework_failed: 作业提交失败 #added by bai
label_bidding_homework_committed: 你已经提交过作业,不能重复提交!
label_bidding_fail: 应标失败,该项目已经应标
label_bidding_homework_fail: 作业提交失败,该作业已经被提交!