重复提交问题

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 :watchers
helper :attachments helper :attachments
include AttachmentsHelper include AttachmentsHelper
include ApplicationHelper
helper :projects helper :projects
helper :words helper :words
def index 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) 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 = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
@homework = HomeworkAttach.new
@homework.safe_attributes = params[:homeworkattach] if hadcommittedhomework(User.current.id, @bid.id) == true
@homework.bid_id = @bid.id @homework_flag = l(:label_bidding_homework_committed)
@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 else
@homework_flag = l(:label_bidding_homework_failed) @homework = HomeworkAttach.new
end @homework.safe_attributes = params[:homeworkattach]
if @homework.attachments.empty? @homework.bid_id = @bid.id
@homework.delete @homework.user_id = User.current.id
flash[:error] = l(:no_attachmens_allowed) @homework.save_attachments(params[:attachments])
@homework_flag = l(:no_attachmens_allowed)
# else render_attachment_warning_if_needed(@homework)
end
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 end
@homework_list = @bid.homeworks @homework_list = @bid.homeworks
respond_to do |format| respond_to do |format|
format.html{ format.html{

View File

@ -1489,4 +1489,14 @@ module ApplicationHelper
obj2 = obj1 obj2 = obj1
end end
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 end

View File

@ -69,5 +69,14 @@ module AttachmentsHelper
def deletable? container, user=User.current def deletable? container, user=User.current
User.current.logged? && (container.author == user || user.admin?) User.current.logged? && (container.author == user || user.admin?)
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
retrun true
end
end
end
end end

View File

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

View File

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