0

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?

4

2 に答える 2

4

i had run rake assets:precompile and was running my server in development mode. solution was to rake assets:clean and restart the sever

于 2012-04-11T03:22:12.013 に答える
1

My workaround for this:

 rake assets:precompile
 with //= require jquery_ujs in your app/assets/javascripts/application.js

After the rake, remove the line from app/assets/javascripts/application.js and start the server. Now it should work as expected.

于 2012-07-25T14:44:36.313 に答える