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

Commit 5c151dc

Browse files
committed
add/remove track: remove hack
1 parent 19b1b34 commit 5c151dc

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

app/assets/javascripts/components/mvp.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ jQuery(function($) {
4242
initializeAutocomplete('competition_tracks_attributes_'+ i +'_end_city_attributes_name');
4343
}
4444

45+
// TODO: this is nasty... can we make it cleaner?
4546
nestedForm = $('.tracks_form').last().clone();
46-
47-
// remove empty-field if edit
48-
if ($('.tracks_form').length > 1) {
49-
$('.tracks_form').last().remove();
50-
}
47+
nestedForm.find("input").val("");
48+
nestedForm.find(".has-error").removeClass("has-error");
49+
nestedForm.find(".help-block").remove();
50+
destroy_link = nestedForm.find(".destroy_track");
51+
destroy_link.attr('data-confirm', '');
52+
destroy_link.attr('data-method', '');
53+
destroy_link.attr("href", "#");
5154

5255
$(".destroy_track:first").remove();
5356
$('body').on('click', '.destroy_track', function(e) {

app/concepts/competition/contract.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ def published?
6262
end
6363

6464
def prepopulate_tracks!(_options)
65-
2.times do
66-
track = Track.new
67-
track.build_start_city
68-
track.build_end_city
69-
tracks << track
70-
end
65+
track = Track.new
66+
track.build_start_city
67+
track.build_end_city
68+
tracks << track
7169
end
7270

7371
def populate_city!(options)
@@ -98,10 +96,7 @@ class Update < Create
9896
private
9997

10098
def prepopulate_tracks!(_options)
101-
track = Track.new
102-
track.build_start_city
103-
track.build_end_city
104-
tracks << track
99+
tracks = tracks
105100
end
106101
end
107102
end

0 commit comments

Comments
 (0)