Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Created October 19, 2010 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramontayag/634533 to your computer and use it in GitHub Desktop.
Save ramontayag/634533 to your computer and use it in GitHub Desktop.
$("#resize-image-dialog").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: false,
buttons: {
'Resize': function() {
var dataString = {
"width": $('#resize-image-dialog input#width').val(),
"height": $('#resize-image-dialog input#height').val()
};
$.ajax({
type: "GET",
url: "/images/" + $('#resize-image-dialog input#id').val() + ".js",
data: dataString,
success: function() {
}
});
},
'Close': function() {
$(this).dialog('close');
}
},
close: function() {
}
});
$.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});
$(function() {
// UJS authenticity token fix: add the authenticy_token parameter
// expected by any Rails POST request.
$(document).ajaxSend(function(event, request, settings) {
// do nothing if this is a GET request. Rails doesn't need
// the authenticity token, and IE converts the request method
// to POST, just because - with love from redmond.
if (settings.type == 'GET') return;
if (typeof(AUTH_TOKEN) == "undefined") return;
settings.data = settings.data || "";
settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
});
Processing ImagesController#show to js (for 127.0.0.1 at 2010-10-21 13:22:28) [GET]
Parameters: {"format"=>"js", "action"=>"show", "id"=>"42", "height"=>"1", "controller"=>"images", "width"=>"1"}
Domain Load (1.1ms) SELECT * FROM "public"."domains" WHERE ("public"."domains"."name" = 'get.stiltify.dev') LIMIT 1
Site Load (0.7ms) SELECT * FROM "public"."sites" WHERE ("public"."sites"."subdomain" = 'get') LIMIT 1
SQL (0.3ms) SET search_path TO get,public
Image Load (0.7ms) SELECT * FROM "images" WHERE ("images"."id" = 42)
User Load (1.0ms) SELECT * FROM "public"."users" WHERE ("public"."users"."id" = '1') LIMIT 1
SQL (0.3ms) BEGIN
User Update (0.6ms) UPDATE "public"."users" SET "updated_at" = '2010-10-21 05:22:28.574488', "perishable_token" = 'b8ycnlrYKdvW1Vd1mUDa', "last_request_at" = '2010-10-21 05:22:28.573452' WHERE "id" = 1
SQL (14.9ms) COMMIT
SQL (0.4ms) SET search_path TO "$user",public
Completed in 154ms (View: 3, DB: 20) | 406 Not Acceptable [http://get.stiltify.dev/images/42.js?width=1&height=1]
$("#image-link").html(function() {
return "<%= escape_javascript link_to("Image at #{params[:width]}x#{params[:height]} pixels", @image.file.url("#{params[:width]}x#{params[:height]}#")) %>";
});
@ramontayag
Copy link
Author

When I execute the ajax call in ajax.js (lines 13-17), I want the server to return /images/[id].js.
I'm able to get show.js to execute but there's a 406 error. I've looked for fixes in Google but I've several them and they don't work.

  • Rails 2.3.8
  • Enabled Rails UJS
  • I've included rails.js (from the tutorial at andrewcox.org) before application.js (but I've tried it the other way around as well, no difference)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment