Skip to content

Instantly share code, notes, and snippets.

View veritas1's full-sized avatar

Mark Charles veritas1

  • Veritas Labs Ltd
  • Ashford, Kent, UK.
  • 07:45 (UTC +01:00)
View GitHub Profile
@veritas1
veritas1 / application.js
Created December 30, 2012 16:41
For my blog post, using 'accepts_nested_attributes_for' and adding fields dynamically.
function add_field(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + association, "g")
$(link).parent().before(content.replace(regexp, new_id));
}
function remove_field = (link) {
$(link).siblings("input[type=hidden]").val(1);
$(link).closest(".fieldset").hide();
}
@veritas1
veritas1 / factories.rb
Created November 24, 2012 11:21
FactoryGirl with polymorphic associations
FactoryGirl.define do
factory :slideshow_image, class: "Image" do
association :imageable, :factory => :slideshow
# other attributes for slideshow model
end
factory :article_image, class: "Image" do
association :imageable, :factory => :article
# other attributes for article model
end