Skip to content

Instantly share code, notes, and snippets.

View taavo's full-sized avatar

Taavo Smith taavo

View GitHub Profile
@taavo
taavo / rails 3.2.11 params patch
Last active December 11, 2015 00:48 — forked from Unpakt/rails 3.2.11 params patch
Add array support
def repair_empty_param_associations
params.keys.each do |key|
repair_nested_params(params, key, params[key])
end
end
private
def repair_nested_params(current_params, key, value)
if key =~ /^(.*)_attributes$/ && value.nil?
@taavo
taavo / backbone-validation-bootstrap.js.coffee
Created September 7, 2012 13:07 — forked from driehle/backbone-validation-bootstrap.js.coffee
Render error messages of Backbone.Validation for Twitter Bootstrap
_.extend Backbone.Validation.callbacks,
valid: (view, attr, selector) ->
control = view.$('[' + selector + '=' + attr + ']')
group = control.parents(".control-group")
# If the input field is still in an invalid state, don't remove error
if view.model.preValidate(attr, control.val())
return
group.removeClass("error")