<div id="id_number">-</div>
<script type="text/javascript">
$(document).ready(function() {
$('#commendations_click').click(function(evt) {
evt.preventDefault();
window.location = "<%=j commendations_path(format: 'pdf') %>"
+ "?idnumber=" + $('#id_number').html()
+ "&employee_movement_id=" + $('#employee_movements_select').val()
});
$('#empname').autocomplete({
source: $('#empname').data('autocomplete-source'),
select: function( event, ui ) {
$("#empname").val(ui.item.last_name + ', ' + ui.item.first_name + ' ' + ui.item.middle_name);
$("#name").html(ui.item.last_name + ', ' + ui.item.first_name + ' ' + ui.item.middle_name);
$("#id_number").html(ui.item.id_number);
$.ajax({
url: "<%= update_employee_movements_path %>",
data: { id_number : ui.item.id_number },
dataType: "script"
});
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>Name: " + item.last_name + ', ' + item.first_name + ' ' + item.middle_name + "<br>ID: " + item.id_number + "</a>" )
.appendTo( ul );
};
});
</script>
def commendations
emdates = EmployeeMovement.last_2_dates_obtained(params[:employee_movement_id])
date_from = emdates[0].date_obtained
date_to = emdates.length == 1 ? nil : emdates[1].date_obtained
emp = Employee.find_by_id_number(params[:id_number])
...more code below...
end
请看看最后一行。这里,params [:id_number]将返回nil。但是,如果我在URL中将id_number更改为idnumber,并调用params [:idnumber],我将获得相关值。
为什么从我的表彰行动中访问时,id_number会返回nil?这是一个约定吗?在jquery侧或轨道侧的约定?
答案 0 :(得分:1)
HTML代码中的某处,元素的ID为idnumber
而不是id_number
。它不是惯例,而是代码中的拼写错误。