I have form that creates record. Form consists of multiple image upload with Remotipart and multiple other fields.
Problem: When I submit form sometimes it does that 3 times, other time 2 times and mostly it works without problems. I have tried to submit exact field data and images. At first time it works, on the other time it submits 3x times.
I checked some other question. But there was problem with Jquery and repeat time is constant. question here
My form:
<%= form_for(@advertisement, :remote=>"true",:html => {:id=>"new_advertisement","data-parsley-validate" => true,:multipart => true}, remote: true ,format: :json) do |f| %>
<%= f.text_field :name , :'data-parsley-minlength'=>3,:required => true,:placeholder=>" Vārds latviešu valodā*"%>
<div class="column-img-main">
<%= file_field_tag "images[]", type: :file, multiple: false,:id=>"myfile", :required => true%>
<%= image_tag("camera.png")%>
</div>
<div class="column-img-secundar">
<%= file_field_tag "images[]", type: :file, multiple: false,:id=>"myfile2"%>
<%= image_tag("camera.png")%>
</div>
<div class="column-img-secundar">
<%= file_field_tag "images[]", type: :file, multiple: false,:id=>"myfile3"%>
<%= image_tag("camera.png")%>
</div>
<div class="column-img-secundar">
<%= file_field_tag "images[]", type: :file, multiple: false,:id=>"myfile4"%>
<%= image_tag("camera.png")%>
</div>
<%end%>
Controller:
def create
@advertisement = Girl.new(girl_params.merge(service_ids: params[:service_ids], hour_ids: params[:hour_ids]))
respond_to do |format|
if @advertisement.save
if params[:images]
params[:images].each { |image|
@advertisement.pictures.create(image: image)
}
end
@user = User.new
@user.email = @advertisement.email
@user.password = "qzwc551"
@user.role = "advertisement"
@user.save(:validate => false)
@advertisement.update_attribute(:user_id,@user.id)
format.json { render json: @advertisement, status: :created, location: @advertisement }
else
format.json { render json: @advertisement.errors, status: :unprocessable_entity }
end
end
end
Script:
$(document).ready(function() {
return $("#new_advertisement").on("ajax:success", function(e, data, status, xhr) {
$(".hidde-reg").hide();
$('.progress-bar-image').children('img').attr('src', '/assets/progress-bar-right.png');
$(".reg-successfull").show();
$('.form-top').children('h1').css('color', '#9EA19D');
$('.form-top2').children('h1').css('color', '#56B0E8');
}).on("ajax:error", function(e, xhr, status, error) {
// return $("#new_feedback").append("<p>ERROR</p>");
alert("Error registration");
});
});
My log file when form submits itself 2x.
Started POST "/lv/girls.json" for 87.246.167.133 at 2015-04-14 16:52:23 +0300
Processing by GirlsController#create as JSON
Parameters: {"utf8"=>"✓", "girl"=>{"name"=>"zzzzzzzzzzzzzzzzzz", "subname"=>"zzzzzzzzzzzzzzzzzzzzzz", "region_id"=>"32", "country_id"=>"1", "age"=>"44", "height"=>"184", "phone_number"=>"78787878", "weight"=>"84", "bust_size"=>"3", "work1"=>"17", "work2"=>"23", "work3"=>"5", "work4"=>"19", "per_hour"=>"40", "per_night"=>"1899", "email"=>"test7@individualki.eu", "client_age"=>"", "description"=>"c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st", "description_ru"=>"c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st", "terms_of_service"=>"1", "humanizer_question_id"=>"18", "humanizer_answer"=>"Thursday", "identifier"=>"93187"}, "service_ids"=>["2", "3", "6", "7", "9", "11"], "toggler"=>"1", "why"=>"", "locale"=>"lv"}
[1m[35mCountry Load (0.4ms)[0m SELECT `countries`.* FROM `countries` WHERE `countries`.`id` = 1 LIMIT 1
[1m[36m (0.6ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_recomend >= '2015-04-14 16:52:23')[0m
[1m[35m (0.4ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (recomend >= '2015-04-14 16:52:23')
[1m[36m (0.4ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (highlight >= '2015-04-14 16:52:23')[0m
[1m[35m (0.4ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_highlight >= '2015-04-14 16:52:23')
[1m[36mRegion Load (0.2ms)[0m [1mSELECT `regions`.* FROM `regions` WHERE `regions`.`country_id` = 1[0m
[1m[35mService Load (0.6ms)[0m SELECT `services`.* FROM `services` WHERE `services`.`id` IN (2, 3, 6, 7, 9, 11)
[1m[36m (0.2ms)[0m [1mBEGIN[0m
[1m[35mGirl Exists (0.7ms)[0m SELECT 1 AS one FROM `girls` WHERE `girls`.`email` = BINARY 'test7@individualki.eu' LIMIT 1
[1m[36mSQL (2.3ms)[0m [1mINSERT INTO `girls` (`age`, `bust_size`, `country_id`, `created_at`, `description`, `description_ru`, `email`, `expiration`, `height`, `highlight`, `identifier`, `name`, `per_hour`, `per_night`, `phone_number`, `recomend`, `region_id`, `subname`, `updated_at`, `vip_highlight`, `vip_recomend`, `weight`, `work1`, `work2`, `work3`, `work4`) VALUES (44, '3', 1, '2015-04-14 16:52:23', 'c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st', 'c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st', 'test7@individualki.eu', '2015-06-09 16:52:23', 184, '2015-04-14 16:52:23', '93187', 'zzzzzzzzzzzzzzzzzz', 40, 1899, '78787878', '2015-04-14 16:52:23', 32, 'zzzzzzzzzzzzzzzzzzzzzz', '2015-04-14 16:52:23', '2015-04-14 16:52:23', '2015-04-14 16:52:23', 84, '17', '23', '5', '19')[0m
[1m[35mSQL (9.8ms)[0m UPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 2
[1m[36mSQL (0.6ms)[0m [1mUPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 3[0m
[1m[35mSQL (2.0ms)[0m UPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 6
[1m[36mSQL (0.4ms)[0m [1mUPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 7[0m
[1m[35mSQL (0.4ms)[0m UPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 9
[1m[36mSQL (0.4ms)[0m [1mUPDATE `services` SET `girl_id` = 20, `updated_at` = '2015-04-14 16:52:23' WHERE `services`.`id` = 11[0m
[1m[35m (4.0ms)[0m COMMIT
[1m[36m (0.7ms)[0m [1mBEGIN[0m
Started POST "/lv/girls.json" for 87.246.167.133 at 2015-04-14 16:52:24 +0300
[1m[36mActiveRecord::SchemaMigration Load (0.5ms)[0m [1mSELECT `schema_migrations`.* FROM `schema_migrations`[0m
[1m[35mUser Load (1.7ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = '32f836a40b343286363f084bf50bfb4d948ef690e0fca949dd892466592f6f5e' ORDER BY `users`.`id` ASC LIMIT 1
[1m[36mSQL (1.1ms)[0m [1mINSERT INTO `users` (`confirmation_sent_at`, `confirmation_token`, `created_at`, `email`, `encrypted_password`, `role`, `updated_at`) VALUES ('2015-04-14 16:52:24', '32f836a40b343286363f084bf50bfb4d948ef690e0fca949dd892466592f6f5e', '2015-04-14 16:52:23', 'test7@individualki.eu', '$2a$10$DwOYFfRCWToqbYfjDLWPiOM1Mr7H6/0ipwaGyU0v8EhRPY3CDgGi.', 'advertisement', '2015-04-14 16:52:23')[0m
Rendered devise/mailer/confirmation_instructions.html.erb (7.6ms)
Processing by GirlsController#create as JSON
Parameters: {"utf8"=>"✓", "girl"=>{"name"=>"zzzzzzzzzzzzzzzzzz", "subname"=>"zzzzzzzzzzzzzzzzzzzzzz", "region_id"=>"32", "country_id"=>"1", "age"=>"44", "height"=>"184", "phone_number"=>"78787878", "weight"=>"84", "bust_size"=>"3", "work1"=>"17", "work2"=>"23", "work3"=>"5", "work4"=>"19", "per_hour"=>"40", "per_night"=>"1899", "email"=>"test7@individualki.eu", "client_age"=>"", "description"=>"c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st", "description_ru"=>"c@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;stc@[OOzQR^;st", "terms_of_service"=>"1", "humanizer_question_id"=>"18", "humanizer_answer"=>"Thursday", "identifier"=>"93187"}, "service_ids"=>["2", "3", "6", "7", "9", "11"], "toggler"=>"1", "why"=>"", "remotipart_submitted"=>"true", "authenticity_token"=>"PEEwzQVqCSsPandF6QGgIwjtyztvxwVXAcGmpmOYlMQ=", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "images"=>[#<ActionDispatch::Http::UploadedFile:0x00000004edac48 @tempfile=#<Tempfile:/tmp/RackMultipart20150414-508581-a5luu7>, @original_filename="gallery-img2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"images[]\"; filename=\"gallery-img2.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x00000004edab58 @tempfile=#<Tempfile:/tmp/RackMultipart20150414-508581-rv4usr>, @original_filename="gallery-img.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"images[]\"; filename=\"gallery-img.jpg\"\r\nContent-Type: image/jpeg\r\n">], "locale"=>"lv"}
[1m[35mCountry Load (0.5ms)[0m SELECT `countries`.* FROM `countries` WHERE `countries`.`id` = 1 LIMIT 1
[1m[36m (1.3ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_recomend >= '2015-04-14 16:52:25')[0m
[1m[35m (0.8ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (recomend >= '2015-04-14 16:52:25')
[1m[36m (0.6ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (highlight >= '2015-04-14 16:52:25')[0m
[1m[35m (0.6ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_highlight >= '2015-04-14 16:52:25')
[1m[36mRegion Load (0.4ms)[0m [1mSELECT `regions`.* FROM `regions` WHERE `regions`.`country_id` = 1[0m
[1m[35mService Load (1.0ms)[0m SELECT `services`.* FROM `services` WHERE `services`.`id` IN (2, 3, 6, 7, 9, 11)
Devise::Mailer#confirmation_instructions: processed outbound mail in 357.6ms
[1m[36m (0.3ms)[0m [1mBEGIN[0m
[1m[35mGirl Exists (1.0ms)[0m SELECT 1 AS one FROM `girls` WHERE `girls`.`email` = BINARY 'test7@individualki.eu' LIMIT 1
[1m[36m (0.4ms)[0m [1mROLLBACK[0m
Completed 422 **Unprocessable Entity** in 338ms (Views: 0.7ms | ActiveRecord: 56.6ms)
Unprocessable Entity is because e-mail is already taken.
I am out of ideas that causes this problem.
Any help would be great. Thanks
Aucun commentaire:
Enregistrer un commentaire