我的select_tag假设在选择项目时自动发布。它确实如此,但是当我查看byebug中的params时,我会在params中找到一个空id而不是所选的id。知道我错过了什么吗?
在我受到批评之前,我确实知道应该将很多内容转移到控制器上。 :)我打算搬家。
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 :(得分: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>