Image location when loaded by javascript in a rails project
I have a javascript plugin in my rails project that loads an image this way:
$('.datepicker').after('<img class="datepickericon" src="images/icons/calendar开发者_运维技巧.png" alt="calendar" />');
Unfortunately in a rails project this image location will point to a path relative to the view where the javascript is loaded. So the pointed location is something like
"admin/images/icons/calendar.png"
I know i could change the value of src to something like
"../public/images/[etc]/calendar.png"
This would work, but it is dependent on the amount of namespaces etc. I don't like to change the code of a plugin every time a use it for different situations.
So what i am looking for is a lasting solution to this image/file location problem when loading something in a (rails) project through javascript. Ofc, no absolute paths or ruby code in my javascript files.
You have a relative url. You want:
src="/images/icons/calendar.png"
精彩评论