0

我正在开发 Rails 3 应用程序。这里有一个视图显示用户上传的所有 excel 文件。执行所有复选框选定文件的按钮已经存在,每个文件分别删除。现在我应该添加一个“删除”按钮来删除选定的文件。我添加了按钮 n 修改了此表单调用的函数,现在只是显示“执行中”和“删除中”,以检查第二个“删除”按钮是否具有功能。但是每次单击删除时,它仅在 cmd 中打印“执行中”。我猜想在视图“列表”中编写的 AJAX 相关代码是问题所在。请帮忙!!告诉我为什么它总是会执行?相关代码在这里:

PS:我在controller.rb中也使用过if params[:commit]="Delete"& if params[:delete_button],但没有帮助

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>&nbsp;</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>&nbsp;</div>
<% end %>

控制器.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  
4

1 回答 1

0

我意识到它必须与 AJAX 做一些事情,Form.serialize(this)它可以序列化所有内容。即它调用视图中第一个按钮的功能,而不管是否存在提交按钮

于 2013-09-18T09:29:26.880 回答