0
嘗試向我的控制器之一提交Ajax請求時,狀態爲404 Not Found。Rails 3中的jQuery Ajax
這裏是我的形式:
<%= nested_form_for @estimate do |f| %>
<%= f.label :date %><br />
<%= f.text_field :date %><br />
<%= f.label :job_name %><br />
<%= f.text_field :job_name %><br />
<%= f.fields_for :items do |builder| %>
<%= builder.label :properties %><br />
<%= builder.text_field :properties, :id => "properties_field" %><br />
<%= builder.label :height %><br />
<%= builder.text_field :height, :id => "height_field" %><br />
<%= builder.label :letter_quantity %><br />
<%= builder.text_field :letter_quantity, :id => "letter_quantity_field" %>
<%= builder.link_to_remove "Remove this item" %>
<% end %>
<%= f.link_to_add "Add a item", :items %>
<%= f.submit "Add item" %>
<% end %>
<script type="text/javascript">
$("#letter_quantity_field").blur(function() {
var height = $("height_field").val();
var properties = $("properties_field").val();
$.ajax({
url: '/estimates/calculateCost?height=' + height + '&properties=' + properties , type: 'get', dataType: 'html',
processData: false,
success: function(data) {
if (data == "record_not_found") {
alert("Record not found");
}
else {
$("#letter_quantity_field").val(data);
}
}
});
});
</script>
這裏是我的控制器:
class EstimatesController < ApplicationController
.
.
.
def calculateCost
cost_data = CostData.find_by_properties_and_find_by_height(params[:properties], params[:height])
if @cost_data.blank?
render :text => "record_not_found"
else
render :text => @cost_data.unit_price
end
end
end
我一直在谷歌搜索在這一個小時。任何幫助將不勝感激。
你是如何指定你的路線? – Pravin