I dynamically generate the title of a video from the embedly API in my application.js file with:
$(this).parent().prepend('<p>'+ oembed.title + '<p>');
Bear in mind that code is taken out of context.
Now I want to make the title a link to that video’s show view. However, I don’t believe I have access to named routes in my application.js file. What should I do?
This is a long way of going about it (hopefully someone else comes up with a better solution), but perhaps in the view where the title is being generated, you can include the URL to the show view in a
data-attribute, generated by ERB (Or Haml or whatever). For example:Then you can access the
data-show-urlvia Javascript in yourapplication.jscode and use it to generate the link.