mirror of https://github.com/fspc/BikeShed-1.git
Jason Denney
8 years ago
committed by
GitHub
18 changed files with 1545 additions and 160 deletions
@ -1,31 +1,11 @@ |
|||||
$('.btn').button(); |
$('.btn').button(); |
||||
|
|
||||
$("#add_bike_submit").click(function(){ |
$("#add_bike_form").ajaxForm({ |
||||
|
|
||||
json_data = { bikes: [{ |
|
||||
serial_number: $("#serial_number").val(), |
|
||||
bike_brand_id: parseInt($("#bike_brand_id").val()), |
|
||||
shop_id: parseInt($("#shop_id").val()), |
|
||||
model: $("#model").val(), |
|
||||
bike_style_id: parseInt($('input[name=bike_style]:checked').val()), |
|
||||
seat_tube_height: parseFloat($("#seat_tube_height").val()), |
|
||||
bike_condition_id: parseInt($('input[name=bike_condition]:checked').val()), |
|
||||
bike_purpose_id: 1, |
|
||||
bike_wheel_size_id: parseInt($("#bike_wheel_size_id").val()), |
|
||||
}]}; |
|
||||
|
|
||||
$.ajax({ |
|
||||
url: $("#add_bike_submit").data("url"), |
|
||||
type: "POST", |
|
||||
data: JSON.stringify(json_data), |
|
||||
contentType: 'application/json', |
|
||||
dataType: "json", |
dataType: "json", |
||||
success: function(data, status, xhr){ |
success: function(data){ |
||||
window.location = data.bikes[0].id + "?add_bike=1"; |
window.location = data.bikes[0].id + "?add_bike=1"; |
||||
}, |
}, |
||||
error: function(data, status ){ |
error: function(data){ |
||||
displayFormErrors(data.responseJSON); |
displayFormErrors(data.responseJSON); |
||||
} |
} |
||||
}); |
}) |
||||
|
|
||||
}); |
|
@ -1,8 +1,10 @@ |
|||||
function displayFormErrors(data){ |
function displayFormErrors(data, form){ |
||||
|
if(form){ |
||||
|
$(form).find(".form-group.has-error").removeClass("has-error").find(".help-block").html(""); |
||||
|
} |
||||
if(data.errors != undefined ){ |
if(data.errors != undefined ){ |
||||
$.each(data.errors, function(field, errorMsg) { |
$.each(data.errors, function(field, errorMsg) { |
||||
$("#"+field).closest(".form-group").addClass("has-error"); |
$("#"+field).closest(".form-group").addClass("has-error").find(".help-block").html(errorMsg.join(", ")); |
||||
$("#"+field).siblings(".help-block").html(errorMsg); |
|
||||
}); |
}); |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,11 @@ |
|||||
|
class AddAttachmentAvatarToUsers < ActiveRecord::Migration |
||||
|
def self.up |
||||
|
change_table :users do |t| |
||||
|
t.attachment :avatar |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def self.down |
||||
|
remove_attachment :users, :avatar |
||||
|
end |
||||
|
end |
@ -0,0 +1,11 @@ |
|||||
|
class AddAttachmentPhotoToBikes < ActiveRecord::Migration |
||||
|
def self.up |
||||
|
change_table :bikes do |t| |
||||
|
t.attachment :photo |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def self.down |
||||
|
remove_attachment :bikes, :photo |
||||
|
end |
||||
|
end |
File diff suppressed because it is too large
Loading…
Reference in new issue