Ruby on the rails, the background image does not work the first time

advertisements

I have the follow code:

<div class="photoProfile" style="background-image: url(<%= @user.image.url %>)"></div>

the variable @user.image.url always has value, but the first time, is not attached to the background-image, I need refresh the page and now the image is loaded perfectly.

Some one has and idea of this issue?


I have the same issue, and change "asset_path" to "asset_url".

Before) <div style="background-image: url(<%= **asset_path**(get_img(object)) %>)">

After) <div style="background-image: url(<%= **asset_url**(get_img(object)) %>)">

but, I cant't understand why it works.