Skip to content

Instantly share code, notes, and snippets.

@roblingle
Created June 4, 2014 21:06
Show Gist options
  • Save roblingle/96152e7dc5a11f66becd to your computer and use it in GitHub Desktop.
Save roblingle/96152e7dc5a11f66becd to your computer and use it in GitHub Desktop.
Ran into problems with bootstrap-editable-rails in a turbolinks app. Could also happen in x-editable-rails. After a page change, attempting to use the editable fields would result in Uncaught RangeError: Maximum call stack size exceeded. This fixes it by only doing the setup for EditableForm once instead of every page change.
# Be sure to remove bootstrap-editable-rails from application.js
unless EditableForm
EditableForm = undefined
EditableForm = $.fn.editableform.Constructor
EditableForm::saveWithUrlHook = (value) ->
originalUrl = undefined
resource = undefined
originalUrl = @options.url
resource = @options.resource
@options.url = ((_this) ->
(params) ->
obj = undefined
if typeof originalUrl is "function"
originalUrl.call _this.options.scope, params
else if (originalUrl?) and _this.options.send isnt "never"
obj = {}
obj[params.name] = params.value
if resource
params[resource] = obj
else
params = obj
delete params.name
delete params.value
delete params.pk
$.ajax $.extend(
url: originalUrl
data: params
type: "PUT"
dataType: "json"
, _this.options.ajaxOptions)
)(this)
@saveWithoutUrlHook value
EditableForm::saveWithoutUrlHook = EditableForm::save
EditableForm::save = EditableForm::saveWithUrlHook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment