I have the following form:
= form_for([current_user,@company], :remote => true) do |f|
-if @company.errors.any?
#error_explanation
%h2= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:"
%ul
- @company.errors.full_messages.each do |msg|
%li= msg
=f.label :name
=f.text_field :name
=f.label :address
=f.text_area :address, :rows => 3, :cols => 5
=f.label :phone_number
=f.text_field :phone_number
.actions
= f.submit 'Save'
When I click the save button I can see the folllowing in my server log:
Started POST "/users/1/companies" for 127.0.0.1 at 2012-04-04 21:27:50 +0700
Processing by CompaniesController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6ZH9hAUuf5ZTCf8Loc4M/IIl/Etzm7uDGoYbIgCTvhI=", "company"=>{"name"=>"test", "address"=>"test", "phone_number"=>"5454543"}, "commit"=>"Save", "user_id"=>"1"}
(0.2ms) BEGIN
SQL (25.2ms) INSERT INTO "companies" ("address", "name", "phone_number", "url", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["address", "test"], ["name", "test"], ["phone_number", "5454543"], ["url", nil], ["user_id", nil]]
(1.6ms) COMMIT
Rendered companies/create.js.erb (0.7ms)
Completed 200 OK in 41ms (Views: 8.1ms | ActiveRecord: 27.0ms)
Started POST "/users/1/companies" for 127.0.0.1 at 2012-04-04 21:27:50 +0700
Processing by CompaniesController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6ZH9hAUuf5ZTCf8Loc4M/IIl/Etzm7uDGoYbIgCTvhI=", "company"=>{"name"=>"test", "address"=>"test", "phone_number"=>"5454543"}, "commit"=>"Save", "user_id"=>"1"}
(0.7ms) BEGIN
SQL (2.7ms) INSERT INTO "companies" ("address", "name", "phone_number", "url", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["address", "test"], ["name", "test"], ["phone_number", "5454543"], ["url", nil], ["user_id", nil]]
(12.8ms) COMMIT
Rendered companies/create.js.erb (0.1ms)
Completed 200 OK in 30ms (Views: 10.5ms | ActiveRecord: 16.1ms)
Which means the form is being submitted twice. I have removed the assets folder from my public directory. I have also checked the html rendered on the page and there is no double inclusion of jquery or other dependencies.
Why is it being submitted twice?