我在生产环境中遇到过这个奇怪的错误。我在Ruby on Rails应用程序中使用GET方法有几个AJAX请求,现在我决定更改此安全错误漏洞。我将大多数请求更改为POST。在本地环境和演示环境中,一切都运行良好,几乎与生产环境相同。
请求:(CoffeeScript)
$(".vehicle_make_dropdown").on "change", ->
$.ajax(
url: "/get_maker_models"
data:
maker: $("#entry_vehicle_make").val()
method: "POST" // this was "GET" before!
dataType: "JSON"
).success( (json) ->
i = 0
$(".vehicle_model_dropdown").html("")
$(".vehicle_model_dropdown").prop("disabled", false)
while(i < json.length)
$(".vehicle_model_dropdown").append("<option value='#{json[i]["title"]}'>#{json[i]['title']}</option>")
i++
).error( (resp) ->
console.log("error")
)
接收者:(Ruby(RoR))
def get_maker_models
@models = VehicleMaker.find_by(title: params[:maker]).vehicle_models.order("title ASC")
render json: @models
end
路线:
post "get_maker_models" => 'credit_form#get_maker_models'
但在日志中我还是这样:
I, [2014-09-18T14:08:47.852487 #28300] INFO -- : Started GET "/get_maker_models/" for 80.232.253.212 at 2014-09-18 14:08:47 +0400
I, [2014-09-18T14:08:47.856224 #28300] INFO -- : Processing by ApplicationController#routing_error as JSON
I, [2014-09-18T14:08:47.856329 #28300] INFO -- : Parameters: {"path"=>"get_maker_models"}
I, [2014-09-18T14:08:47.863482 #28300] INFO -- : Rendered error/404.html.erb within layouts/application (1.1ms)
I, [2014-09-18T14:08:47.868535 #28300] INFO -- : Rendered layouts/shared/_audit_start.html.haml (1.1ms)
I, [2014-09-18T14:08:47.882499 #28300] INFO -- : Rendered layouts/shared/_main_menu.html.haml (1.5ms)
I, [2014-09-18T14:08:47.882696 #28300] INFO -- : Rendered layouts/shared/_header.html.haml (11.7ms)
I, [2014-09-18T14:08:47.902478 #28300] INFO -- : Rendered layouts/shared/_mini_faq.html.haml (8.9ms)
I, [2014-09-18T14:08:47.907767 #28300] INFO -- : Rendered layouts/shared/_main_menu.html.haml (0.4ms)
I, [2014-09-18T14:08:47.914008 #28300] INFO -- : Rendered layouts/shared/_scripts.html.erb (1.1ms)
I, [2014-09-18T14:08:47.914220 #28300] INFO -- : Rendered layouts/shared/_footer.html.haml (29.0ms)
I, [2014-09-18T14:08:47.917616 #28300] INFO -- : Rendered layouts/shared/_audit_end.html.haml (0.9ms)
I, [2014-09-18T14:08:47.917902 #28300] INFO -- : Completed 404 Not Found in 61ms (Views: 55.6ms | ActiveRecord: 3.3ms)
我试过了:
使用生产环境重新编译资产。
编辑:
在ajax请求中,我将方法更改为
答案 0 :(得分:1)
重建资产时,您是否指定了环境?作为rake assets:precompile RAILS_ENV=production
?
编辑:
$ .ajax应该type
来指定请求的类型而不是method
。
默认是GET,所以这可能就是问题所在。