2017-01-25 31 views
1

我的select_tag是假設選擇一個項目時自動發佈。它的確如此,但是當我在byebug中查看參數時,我在參數中獲得了一個空id,而不是所選的id。任何想法我失蹤?select_tag沒有通過參數

在我受到很多批評之前,我確實知道很多應該轉移到控制器。 :)我打算移動它。

PARAMS:

{"utf8"=>"✓", "authenticity_token"=>"jeuwTKfou9qOs8Gj5M4TKOs0Ed7kjeewuqqslKAXonw6T4MRafeurp0pOHFHgPoDV000ExqFnOQfF8S/8oV5/Q==", "id"=>"", "method"=>"post", "controller"=>"call_track", "action"=>"associate"} 

選擇有問題的標籤:

select_tag :id, options_for_select(@project_job_selector),{:onchange => 'this.form.submit();', include_blank: true} 

@project_job_selector:

def cache_jobs 

    @root_jobs = Job.where(active:true,parent_id: nil).order("name") 

    @project_job_selector = [] 

    @root_jobs.each {|job| 
     if job.children.size > 0 
     addmain=0 
     job.children.each {|child| 
      if (child.active?) 
      addmain+=1 
      end 
     } 
     name = (addmain >= 1 ? job.name + ' (Main Job)' : job.name) 
     else 
     name = job.name 
     end 
     @project_job_selector << [name, job.id] 
     job.children.each {|subjob| 
     @project_job_selector << [' -- ' + subjob.name, subjob.id] if subjob.active? 
     } 
    } 
    @project_job_selector 
    end 

整體觀:

<script> 
    $(document).ready(function() { 
    $('#call_track_table').DataTable({ 
     responsive: true, 
     scrollY: 400, 
     paging: false 
    }); 
    }); 

    $(function() { 
     $("#dialog").dialog({ 
      autoOpen: false, 
      modal: true, 
      width: ($(window).width() - 300), 
      height: ($(window).height() - 100), 
      buttons: { 
       'Cancel': function() { 
        $(this).dialog('close'); 
       } 
      } 
     }); 
     $(".dialogify").on("click", function(e) { 
      e.preventDefault(); 
      $("#dialog").html(""); 
      $("#dialog").dialog("option", "title", "Loading....").dialog("open"); 
      $("#dialog").load(this.href, function() { 
       $(this).dialog("option", "title", 'Edit Task'); 
       $(this).find("title").remove(); 
      }); 
     }); 
    }); 
</script> 
<h1>Live Call Track</h1> 
<%= form_tag(controller: :call_track, action: :associate, method: :post) do %> 
<table id="call_track_table" class="display responsive no-wrap" cellspacing="0" width="100%" > 
    <thead> 
    <tr> 
     <th>Date</th> 
     <th>Start Time</th> 
     <th>Duration</th> 
     <th>Extension</th> 
     <th>Direction</th> 
     <th>Support Call</th> 
     <th>Dialed Number</th> 
     <th>Caller ID</th> 
     <th>Project</th> 
    </tr> 
    </thead> 
    <tfoot> 
    <tr> 
     <th>Date</th> 
     <th>Start Time</th> 
     <th>Duration</th> 
     <th>Extension</th> 
     <th>Direction</th> 
     <th>Support Call</th> 
     <th>Dialed Number</th> 
     <th>Caller ID</th> 
     <th>Project</th> 
    </tr> 
    </tfoot> 
    <tbody> 

    <% @rs.each do |call| %> 

    <% if User.where(:shoretel_ext => call['Extension']).present? then username = User.where(:shoretel_ext => call['Extension']).pluck(:nickname) else username = call['Extension'] end %> 
    <% if User.where(:shoretel_ext => call['DialedNumber']).present? then dialednumber = User.where(:shoretel_ext => call['DialedNumber']).pluck(:nickname) else dialednumber = call['DialedNumber'] end %> 
    <% if User.where(:shoretel_ext => call['CallerID']).present? then callerid = User.where(:shoretel_ext => call['CallerID']).pluck(:nickname) else callerid = call['CallerID'] end %> 
     <% 
     if username[0].length > 2 then 
      username = username[0] 
     end 
     if dialednumber[0].length > 2 then 
      dialednumber = dialednumber[0] 
     end 
     if callerid[0].length > 2 then 
      callerid = callerid[0] 
     end 

     %> 
     <% 
     if call['CallType'] == 'Inbound' then 
     phone = call['CallerID'].to_s 
     phone.slice!(0,2) 
     if Job.where("replace(replace(replace(replace(phone_main, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_back, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_cell, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_emergency, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_dsl, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "'").present? then 
      job = Job.where("replace(replace(replace(replace(phone_main, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_back, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_cell, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_emergency, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_dsl, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "'").pluck(:id) 
      job = job[0].to_i 
     elsif ClientPhone.where(:phone => phone) 
      job = ClientPhone.where(:phone => phone).pluck(:client_id) 
      job = job[0].to_i 
     else 
      job = 0 
     end 

     if job > 0 then 
      job_name = Job.find_by_id(job) 
      job_name = job_name.name 
     end 
     end 
     if call['CallType'] == 'Outbound' then 
     phone = call['DialedNumber'].to_s 
     phone.slice!(0,2) 
     if Job.where("replace(replace(replace(replace(phone_main, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_back, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_cell, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_emergency, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_dsl, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "'").present? then 
      job = Job.where("replace(replace(replace(replace(phone_main, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_back, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_cell, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_emergency, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "' OR replace(replace(replace(replace(phone_dsl, ' ', ''), '-', ''),'(',''),')','') = '" + phone + "'").pluck(:id) 
      job = job[0].to_i 
     elsif ClientPhone.where(:phone => phone) 
      job = ClientPhone.where(:phone => phone).pluck(:client_id) 
      job = job[0].to_i 
     else 
      job = 0 
     end 

     if job > 0 then 
      job_name = Job.find_by_id(job) 
      job_name = job_name.name 
     end 
     end 
     if call['CallType'] == 'ExtToExt' then 
     job = -1 
     end 
    %> 
     <% if call['Extension'].to_i != 4010 then %> 
    <tr> 
    <td><%= link_to call['StartTime'].strftime('%Y-%m-%d'), {:controller => :call_track, :action => :call_segments, :call_id => call['ID'] }, class: 'dialogify' %></td> 
    <td><%= call['StartTime'].strftime('%I:%M %p') %></td> 
    <td><%= TimeDifference.between(call['StartTime'], call['EndTime']).in_minutes %> Minutes</td> 
    <td><%= username %></td> 
    <td><%= call['CallType'] %></td> 
    <td><%= if call['WorkgroupCall'] == 1 then 'True' else 'False' end %></td> 
    <td><%= dialednumber %></td> 
    <td><%= callerid %></td> 
    <td><%= if job == 0 then select_tag :id, options_for_select(@project_job_selector),{:onchange => 'this.form.submit();', include_blank: true} elsif job == -1 then '' else job_name.to_s end %></td> 
    </tr> 
    <%end%> 
    <%end%> 
    </tbody> 
</table> 
    <%end%> 
<div id="dialog"></div> 
<br> 
<br> 
<div id="historical_form"> 

</div> 

這是Rails 4

+0

你在'@project_job_selector'中有什麼值? 。也可以嘗試, 'select_tag「id」,options_for_select(@project_job_selector),{:onchange =>'this.form.submit();',include_blank:true}' – Sravan

+0

我添加了上述@project_job_selector的代碼。它位於ApplicationController中並在多個地方使用。我試着在id周圍添加引號並且沒有什麼區別 –

+0

在你的視圖中執行'<%= @project_job_selector%>'並檢查它裏面是否有數據? – Sravan

回答

0

把我的form_tag放在表格單元格內固定它。

<tr> 
    <td><%= link_to call['StartTime'].strftime('%Y-%m-%d'), {:controller => :call_track, :action => :call_segments, :call_id => call['ID'] }, class: 'dialogify' %></td> 
    <td><%= call['StartTime'].strftime('%I:%M %p') %></td> 
    <td><%= TimeDifference.between(call['StartTime'], call['EndTime']).in_minutes %> Minutes</td> 
    <td><%= username %></td> 
    <td><%= call['CallType'] %></td> 
    <td><%= if call['WorkgroupCall'] == 1 then 'True' else 'False' end %></td> 
    <td><%= dialednumber %></td> 
    <td><%= callerid %></td> 
    <td><%= form_tag({controller: "call_track", action: "associate"}, method: "post") do %><%= if job == 0 then select_tag(:job_id,options_for_select(@jobs),{include_blank: true,:onchange => 'this.form.submit();'}) elsif job == -1 then '' else job_name.to_s end %><%end%></td> 
    </tr>