Question

.agency{style: "background-image: url(#{image_path "transport-logos/#{service.agency_name}.png"})"}

When service.agency_name contains spaces, I get invalid resource names, such as transport-logos/some name.png instead of transport-logos/some%20name.png.

How do I convert spaces to %20 in HAML?

Was it helpful?

Solution

Using

URI.encode("some name")

will give some%20name

Change your code as below,

.agency{style: "background-image: url(#{image_path "transport-logos/#{URI.encode(service.agency_name)}.png"})"}

OTHER TIPS

Use the CGI.escape method

.agency{style: "background-image: url(#{image_path "transport-logos/#{CGI.escape(service.agency_name)}.png"})"}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top