我正在使用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 !@excel_errors[file_id].nil? && !@excel_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 !@excel_errors[file_id].nil? && !@excel_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]=@execmsg
#end
# puts @execmsg
elsif !params[:delete_button].nil?
puts "in delete"
end
end
答案 0 :(得分:0)
我意识到必须对AJAX的Form.serialize(this)
做一些事情,它将所有内容序列化。即无论是否存在提交按钮,它都会调用视图中第一个按钮的功能