Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route to static file in Play! 2.0

I'm trying to make a route to a specific static file but everything I'm trying ends with an error.

I've made 3 different attempts:

1.

GET /file   staticFile:/public/html/file.html 

The error I get:

Compilation error string matching regex `\z' expected but `:' found 

2.

GET /file   controllers.Assets.at(path="/public/html", "file.html") 

The error I get:

Compilation error Identifier expected 

3.

GET /file   controllers.Assets.at(path="/public/html", file="file.html") 

The error I get: (and this is the weirdest)

Compilation error not enough arguments for method at: (path: String, file: String)play.api.mvc.Call. Unspecified value parameter file. 

The weird part about the 3rd error is that it's thrown in a different file (app/views/main.scala.html) on the following line:

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> 

All of these methods were found in the official documentation and/or threads here on stackoverflow. What am I missing here?

Thanks.

like image 603
Nitzan Tomer Avatar asked Mar 20 '12 18:03

Nitzan Tomer


2 Answers

IIRC, change

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> 

To

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/", "main.css")"> 

I am talking about your third attempt

Also, watch out for extra /

EDIT

GET /assets/main.css    controllers.Assets.at(path="/public", file="/stylesheets/main.css") 

Assuming your resource is at /public/stylesheets/main.css

like image 64
Jamil Avatar answered Oct 04 '22 18:10

Jamil


I am not totally sure if this is correct, but this is what we are using to map a public folder containing our images, javascripts... etc..

# Map static resources from the /public folder to the /assets URL path GET     /assets/*file               controllers.Assets.at(path="/public", file) 
like image 40
Nick Avatar answered Oct 04 '22 16:10

Nick