2013-04-24 1 views
0

레일즈 3 앱에서 작업하고 있습니다. 여기서보기는 사용자가 업로드 한 모든 Excel 파일을 표시합니다. 선택한 모든 파일을 실행하는 버튼에는 이미 각 파일에 대한 삭제가 있습니다.. 지금 내가 선택한 파일을 삭제하는 '삭제'버튼을 추가해야합니다. 버튼 n을 추가했습니다.이 양식으로 호출 된 함수를 수정했습니다. "실행 중"과 "삭제 중"을 표시하려면 두 번째 '삭제'버튼이 functioanal인지 확인하십시오. 그러나 삭제가 클릭 될 때마다 cmd에서만 "실행 중"으로 인쇄됩니다. 나는 AJAX 관련 코드가 뷰 'list'에 쓰여있는 것이 문제라고 생각한다. Pls 도움! 그게 왜 항상 실행될 지 말해봐. 관련 코드는 여기에 있습니다 :제출 버튼이 이전 버튼의 기능을 호출합니다.

PS : 나는 또한에 controller.rb 그러나 didnt 한 도움에 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 [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>&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 %> 

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 
+0

@Dave Newton, Hey Dave 질문에서 편집 한 내용을 알 수 있습니까? –

+0

예, 편집이 완료되었을 때 나타나는 링크를 클릭하십시오. 제목 (우리는 이미 태그가 있음)에서 태그를 제거하고, 파일 이름에서 거대한 헤더를 제거하고, 관련이없는 태그를 제거했습니다. 필자가 전화를 사용하지 않았다면 질문의 초점을 좁히기 위해 관련성이없는 많은 HTML과 코드를 제거했을 것입니다. [Small, Self-Contained, Correct Example] (http://sscce.org/)에서 더 많은 정보를 제공하지만, 간단히 말해서 질문에는 해당 질문을 이해하는 데 필요한 컨텍스트 만 포함되어야한다는 것입니다. –

답변

0

나는 모든 것을 직렬화하는 AJAX의 Form.serialize(this)으로 뭔가를해야한다는 것을 깨달았다. 즉, 제출 버튼이 없어도보기의 첫 번째 버튼 기능을 호출합니다.

관련 문제