Skip to content

Instantly share code, notes, and snippets.

@itsbth
Created December 24, 2011 13:02
Show Gist options
  • Select an option

  • Save itsbth/1517301 to your computer and use it in GitHub Desktop.

Select an option

Save itsbth/1517301 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$ ->
$('#dupe_image').data('n', 0).attr(id: 'dupe_image_0', name: 'dupe[image][0]').change ->
$this = $(this)
n = $this.data('n') + 1
parent = $this.unbind('change').parents('.clearfix')[0]
$parent = $(parent)
$node = $(parent).clone()
$node.children('input')
.attr(name: "dupe[image][#{n}]", id: "dupe_image_#{n}").data('n', n).change(arguments.callee)
$parent.after($node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment