0
votes

A User has a photo. When they update their photo, it is successfully updating in the database however it does not update in the browser. If I open a different browser, I can see that it has been updated. But this problem is occurring in all browsers. Is there any way that I can force Rails to show the new image after it is updated?

I am using standard code in the controller that updates the user_params.

From Heroku Console

Started PATCH "/community/8" for
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7zUIz7zxmYm8dssdSEGDHbddsieyVnwix8z/Fx/sxVzXqoLtxNq+3sxfps8RsE6pV/XN5V46qhJdo1VpKLK8pF3wDmZNg==", "user"=>{"profile"=>"Cool dude. Lives under ocean.", "photo"=>#, @original_filename="som-tam-thai.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"som-tam-thai.jpg\"\r\nContent-Type: image/jpeg\r\n">, "gender_type"=>"male", "country"=>"US"}, "id"=>"8"}
[1m[35mSQL (1.5ms)[0m UPDATE "users" SET "photo" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["photo", "8.jpg"], ["updated_at", "2017-03-04 18:34:20.835477"], ["id", 8]]

If I update the other user attributes that are strings, they will be shown immediately. Only the photo requires that the browser be restarted for the changes to be shown.

2
can you show your code snipped for rails server and client side - user3775217
@user3775217 please see edited question - Timmy Von Heiss

2 Answers

0
votes

To see the new, updated image, you need to use redirect_to method. It should redirect to profile of user with this particular id.

def edit
  @user = User.find(params[:id])
end

def update
  @user = User.find(params[:id])

  if @user.update(user_params)
    redirect_to @user
  else
    render 'edit'
  end
end
0
votes

The problem was that I had created a method in Carrierwave that changed the filename of the uploaded image to the equivalent of user.id which is why above you see [["photo", "8.jpg"]. So the new image is being given the same name. After removing this method, the problem ceased.

I am still wondering if there is a way to force Rails to realize that the image has changed, even though the name is the same, and reload it?