Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
add/remove track: remove hack
Browse files Browse the repository at this point in the history
  • Loading branch information
norydev committed Aug 13, 2016
1 parent 19b1b34 commit 5c151dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 8 additions & 5 deletions app/assets/javascripts/components/mvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ jQuery(function($) {
initializeAutocomplete('competition_tracks_attributes_'+ i +'_end_city_attributes_name');
}

// TODO: this is nasty... can we make it cleaner?
nestedForm = $('.tracks_form').last().clone();

// remove empty-field if edit
if ($('.tracks_form').length > 1) {
$('.tracks_form').last().remove();
}
nestedForm.find("input").val("");
nestedForm.find(".has-error").removeClass("has-error");
nestedForm.find(".help-block").remove();
destroy_link = nestedForm.find(".destroy_track");
destroy_link.attr('data-confirm', '');
destroy_link.attr('data-method', '');
destroy_link.attr("href", "#");

$(".destroy_track:first").remove();
$('body').on('click', '.destroy_track', function(e) {
Expand Down
15 changes: 5 additions & 10 deletions app/concepts/competition/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ def published?
end

def prepopulate_tracks!(_options)
2.times do
track = Track.new
track.build_start_city
track.build_end_city
tracks << track
end
track = Track.new
track.build_start_city
track.build_end_city
tracks << track
end

def populate_city!(options)
Expand Down Expand Up @@ -98,10 +96,7 @@ class Update < Create
private

def prepopulate_tracks!(_options)
track = Track.new
track.build_start_city
track.build_end_city
tracks << track
tracks = tracks
end
end
end
Expand Down

0 comments on commit 5c151dc

Please sign in to comment.