0
我正在使用Rails 3應用程序。這裏的視圖顯示了用戶上傳的所有excel文件。 執行所有複選框選定文件的按鈕已經出現,每個文件單獨刪除。現在我應該添加一個'刪除'按鈕來刪除選定的文件。我添加了按鈕n,修改了這個形式jus調用的函數,現在顯示「正在執行」和「正在刪除」,檢查第二個「刪除」按鈕是否屬於功能。但每次單擊刪除時,它都會在cmd中打印「執行中」。我猜想在視圖'列表'中寫入的AJAX相關代碼是問題所在。 請幫忙!告訴我爲什麼總是要執行? 相關的代碼是在這裏:添加提交按鈕調用早期按鈕的函數本身
PS:我甲肝使用if params[:commit]="Delete"
& if params[:delete_button]
也controller.rb到,但沒有幫助
list.html.erb(在顯示所有文件視圖)
<% if @files.length > 0 %>
<h2 id='comments'>Uploaded Excel Files are as listed below for Edit/Delete/Execution</h2>
<div id='checkone' class='hide'>Please check atleast one excel file to execute</div>
<% ajax_str = "new Ajax.Request('/account/execute_testcases', {asynchronous:true, evalScripts:true, onComplete:function(request){adjust_sidebar();Element.show('msg');Element.hide('waitid');Element.hide('disableexecuteid');Element.show('executeid');}, onLoading:function(request){Element.show('waitid');Element.hide('msg');Element.hide('executeid');Element.show('disableexecuteid');}, parameters:Form.serialize(this)}); return false;".html_safe %>
<%= form_for 'file_names', :url => {:controller => 'account', :action => 'execute_testcases'}, :remote => true, :html => {:name => 'frmExecute', :onsubmit => ajax_str }, :id =>'execute_tc' do |f| %>
<table>
<% if @file_count > 1 && @error_in_all_files == false %>
<tr>
<td>
<input type='checkbox' name='chkAll' onclick='checkAll();'>
<span class='text'>Check All/Decheck All</span>
</td>
</tr>
<% end %>
</table>
<table class='upload'>
<% for a in @files %>
<tr>
<td>
<% file_id = a.id.to_i %>
<% if(@excel_errors[file_id].nil? || @excel_errors[file_id].empty?) && a.file_type.to_i != 1 %>
<input type='checkbox' name = "excelfile[]" value="<%= a.excel_filename %>,<%= a.excel_filename_with_timestamp %>">
<% else %>
<input type='checkbox' name = "excelfile[]" value="<%= a.excel_filename %>,<%= a.excel_filename_with_timestamp %>" disabled=true>
<% end %>
<a href="open_excel_file/<%= a.id %>" title='Click to open' class='nodecoration'><%= a.excel_filename %></a>
</td>
<td>
<%= link_to(image_tag("/images/b_edit.png", :border => 0, :title => 'Edit'), :action => 'upload_file', :file_id => a.id) %>
</td>
<td>
<a href="delete/<%=a.id %>"><img src='/images/b_drop.png' border=0 title='Delete' onclick="return confirm('This will delete the related reports too. Are you sure to delete?');"></a>
</td>
<td>
<%
if [email protected]_errors[file_id].nil? && [email protected]_errors[file_id].empty?
@joined_excel_errors = @excel_errors[file_id].join(', ')
%>
<a href='#' onclick="show_excel_errors(<%=file_id%>);" title="Error">Error</a>
<% end %>
</td>
</tr>
<tr id="excel_error_<%=file_id %>" style='display:none;'>
<td colspan=4>
<% if [email protected]_errors[file_id].nil? && [email protected]_errors[file_id].empty? %>
<div class="padder">
<% for error_value in @excel_errors[file_id] %>
<font color='maroon'><%= error_value %></font><br>
<% end %>
</div>
<% end %>
</td>
</tr>
<% end %>
<tr><td> </td></tr>
<tr>
<td>
<% if @error_in_all_files == false %>
<span class='executebutton' id='executeid'>
<%= f.submit "Execute", name: 'execute_button', :onclick =>"return checkSelected();" %>
</span>
<span class='deletebutton' id='deleteid'>
<%= f.submit "Delete", name: 'delete_button', :onclick =>"return checkSelected();" %>
</span>
<% end %>
<span id='disableexecuteid' class='executebutton' style='display:none;'>
<input type='submit' value="Execute" disabled="disabled">
</span>
<span id='waitid' style="display:none;" class='text'>
<br>Executing Test Cases...Please wait...<%= image_tag("/images/wait26trans.gif", :border => 0) %>
</span>
<span id='msg' style="display:none;" class='text'>
<br><br> Click here to <%= link_to 'View Test Results', {:controller => 'account', :action => 'recent_test_results'}, :class => 'brownlink' %>
</span>
</td>
</tr>
</table>
<span id='subject_list'>
</span>
<% end %>
<% else %>
No test case sheets found!
<br><br>
<%= link_to '>> Upload File', {:controller => 'account', :action => 'upload_file'}, :class => 'brownlink' %>
<% end %>
<% for i in 1..10 %>
<div> </div>
<% end %>
controller.rb
def execute_testcases
if !params[:execute_button].nil?
puts "in execute"
# file_names = []
# originalfile_filewithtime = []
# original_file_map = {}
# originalfile_filewithtime = params[:excelfile]
......
# SOME CODE HERE
......
# render :update do |page|
# page.replace_html :subject_list, :partial => 'show_output', :locals => {:new_file_map => @new_file_map}
# page.visual_effect :highlight, 'subject_list', :duration => 2
# flash[:display][email protected]
#end
# puts @execmsg
elsif !params[:delete_button].nil?
puts "in delete"
end
end
@Dave Newton,Hey Dave,我可以知道你在問題中編輯了什麼嗎? – 2013-04-24 11:08:24
是的,點擊編輯時的鏈接。我從標題中刪除了標籤(我們已經有了標籤),從文件名中刪除了巨大的標題,並刪除了不相關的標籤。如果我沒有在我的手機上,我也會刪除大量不相關的HTML和代碼來幫助縮小問題的焦點:請參閱[Small,Self-Contained,Correct Example](http://sscce.org/)for更多信息,但簡而言之,問題應該只包括理解它們所需的上下文。 – 2013-04-24 11:40:01