Javascript id_number变量在url中使用时返回null index.html.erb
请看最后一行。这里,params[:id_number]将返回nil。但是,如果我在URL中将id_number更改为idnumber,并调用params[:idnumber],那么我将获得一个相关值Javascript id_number变量在url中使用时返回null index.html.erb,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,请看最后一行。这里,params[:id_number]将返回nil。但是,如果我在URL中将id_number更改为idnumber,并调用params[:idnumber],那么我将获得一个相关值 为什么从我的表彰行动中访问id_编号时会返回零?这方面有约定吗?约定是在jquery端还是rails端 在HTML代码中的某个地方,元素的ID是idnumber而不是ID\u number。这不是一个惯例,而是你的代码中的一个输入错误。你的&应该是URL中的&。您能提供元素#id_numbe
为什么从我的表彰行动中访问id_编号时会返回零?这方面有约定吗?约定是在jquery端还是rails端 在HTML代码中的某个地方,元素的ID是
idnumber
而不是ID\u number
。这不是一个惯例,而是你的代码中的一个输入错误。你的&
应该是URL中的&
。您能提供元素#id_number
的HTML吗?您好@Blazemonger,我已经更新了我的问题#id_number是一个div标签,它会被另一个事件更新。请原谅我的提问,但您如何确定这是一个事实,足以作为OP的答案?Hello@emaillenin,这不是一个打字错误。我注意到id_号码不起作用,所以我把它改成了idnumber。当我在URL中应用更改时,我在从我的操作调用params[]时也会这样做。请看我更新的问题。
<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