javascript - update.js in Rails needs second submit -


i having small (really small) issue rails.

a remote:true update form (calling update.js.erb) needs 2 submissions instead of 1 correctly refresh view.

def update @user = user.find(params[:id]) if @user.update_attributes(update_user_params)   respond_to |format|     format.html {       flash[:success] = "votre profil été mis à jour."       redirect_to @user     }     format.js   end else   render 'edit' end 

end

and here view code (i using method: 'put' because calling homepage, , not edit.html, without it, problem persists):

<%= form_for @user, html: { multipart: true }, remote: true, method: 'put' |f| %>   <%= f.label :location, 'ville', class: 'popover-title' %>   <%= f.select :location, cities_options %>   <%= f.submit "valider", class: 'btn-addon' %> <% end %> 

here's see on submit:

started put "/users/101" 127.0.0.1 @ 2015-08-19 15:25:05 +0200 processing userscontroller#update js parameters: {"utf8"=>"✓", "authenticity_token"=>"hzmd5usgyzvgy4dxqnp0pxf8jpvrk/v+wagtjflhj8rqs0y1ucbzbq9e7hyh20ondn3tk6fxrlgedxynrzevig==", "user"=>{"location"=>"paris"}, "commit"=>"valider", "id"=>"101"} user load (0.1ms)  select  "users".* "users" "users"."id" = ? limit 1  [["id", 101]] user load (0.1ms)  select  "users".* "users" "users"."id" = ? limit 1  [["id", 101]] cache (0.0ms)  select  "users".* "users" "users"."id" = ? limit 1  [["id", "101"]] (0.0ms)  begin transaction user exists (0.1ms)  select  1 one "users" (lower("users"."email") = lower('andrey.soloviev.s@gmail.com') , "users"."id" != 101) limit 1 sql (0.3ms)  update "users" set "location" = ?, "lat" = ?, "lng" = ?, "updated_at" = ? "users"."id" = ?  [["location", "paris"], ["lat", 48.856614], ["lng", 2.3522219], ["updated_at", "2015-08-19 13:25:05.511789"], ["id", 101]] (2.2ms)  commit transaction rendered users/update.js.erb (0.1ms) completed 200 ok in 208ms (views: 4.6ms | activerecord: 2.9ms) 

and finally, here update.js.erb:

$('.location-name').html('<%= current_user.location %>'); 

basic rails js, nothing out of ordinary. above code tells me appears working properly. however, on submit, update.js refreshes location old value database (that there before new one). on second submit see correct value appearing.

if has ideas or solutions, forever grateful.

thank in advance!

i assume current_user helper method on controller, guess cached. switch user object updated. $('.location-name').html('<%= @user.location %>');


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -