Reputation: 712
I have an helper method to get a random image :
def home_random_image
image_path = "app/assets/images/home/"
image_files = Dir.glob("#{image_path}*")
image_files.sample
end
In my view :
style="background-image: url("<%= home_random_image %>");"
But in my my html I get a bad url (without slashs) :
style="background-image: url("app asset images home img.jpg")
Upvotes: 0
Views: 36
Reputation: 4464
Have you tried by replacing the inner "
with '
?
style="background-image: url("<%= home_random_image %>");"
becomes
style="background-image: url('<%= home_random_image %>');"
Upvotes: 1