问题
I have ran in to this strange bug in my production environment. I had several AJAX requests in my Ruby on Rails application with GET methods, now I decided to change this security error holes. I changed most of the requests to POST. Everything works just fine in local environment and in demo environment, which is almost the same as the production environment.
Request: (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")
)
Reciever: (Ruby (RoR))
def get_maker_models
@models = VehicleMaker.find_by(title: params[:maker]).vehicle_models.order("title ASC")
render json: @models
end
Route:
post "get_maker_models" => 'credit_form#get_maker_models'
but in logs i still se this:
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)
I have tried:
- Deploying older version and than again the current one
- Restarting unicorn few times. Nothing seems to work,
- Tried Incognito mode in Chrome.
Recompiled assets with production environmtt.
EDIT:
In ajax request i changed method to type
回答1:
When rebuilding assets, did you specify environment? As rake assets:precompile RAILS_ENV=production
?
EDIT:
$.ajax Should have type
for specifying type of the request instead of method
.
The default is GET, so probably that is the issue here.
http://api.jquery.com/jquery.ajax/
来源:https://stackoverflow.com/questions/25910632/ajax-request-sent-via-get-even-if-method-is-post