Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reverse route a static file?

At first I had this link to a twitter icon:

@{'/public/images/twitter-icon.png'/}

But now I want to show a Twitter-, Facebook- or LinkedIn icon depending on type. So, I created a FastTag that takes the type as a parameter and the code looks like this:

In the view:
#{myApp.icon contact.type/}

FastTag Java Code:
String type = (String) args.get("arg");
out.print("/public/images/" + type + "-icon.png");

It works fine. But, on our build server we run the app with a prefix on the uri like this

http://ourdomain.com/appname/...

Obviously /public/images... won't work here. So I figured I have to ask the Router for the proper address. I've tried the following with no success:

Router.reverse("/public/images/" + type + "-icon.png");
Router.reverse("/public/");
Router.reverse("staticDir:public");

All three result in a NoRouteFoundException. How can I get the correct route for my icons?

In the routes file I have the default route for static files

GET     /public/        staticDir:public
like image 970
Jörgen Lundberg Avatar asked Sep 08 '11 09:09

Jörgen Lundberg


1 Answers

I believe this is what you want:

String imageUrl = Router.reverse(VirtualFile.fromRelativePath("public/images/" + type + "-icon.png"));
like image 191
Scott A Miller Avatar answered Nov 07 '22 07:11

Scott A Miller