Sanmathi
Sanmathi

Reputation: 131

Play Framework tutorial: Cannot resolve symbol 'routes'

I am following the play tutorial and I am stuck at roughly 9 mins. The routes file is not getting resolved I did the same thing as shown in the tutorial but still doesn't work.

package controllers;
import models.Bar;
import play.core.Router;
import play.data.Form;
import play.mvc;
import play.*;
import play.Routes;
import views.html.indes;
public class Application extends Controller {

public static Result index() {
    return ok(index.render("Hello"));
}

public static Result addBar(){
    Bar bar = Form.form(Bar.class).bindFromRequest().get();
    bar.save();
    return redirect(routes)
    }

}

Upvotes: 8

Views: 3480

Answers (5)

Gonzalo
Gonzalo

Reputation: 1876

I have experienced this problem every time I change the scala version of my modules. The easiest way to solve this is:

  • Close Intellij
  • Open a console and run sbt clean compile
  • Open the IDE again and it should work

Upvotes: 0

M-sAnNan
M-sAnNan

Reputation: 804

These steps work for me:

  1. Add following lines to your plugins.sbt file: addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0") under project folder.
  2. Remove .idea folder from your project.
  3. Run the command from cmd sbt gen-idea
  4. Import project again in intelliJ

Upvotes: 1

Kevin
Kevin

Reputation: 1195

Project Structure -> Modules -> Dependencies -> + -> JAR or directories -> target/scala-#.##/classes_managed

Marking this directory as Sources Root/Generated Sources Root did not work for me, as mentioned in some other S/O posts

Upvotes: 6

Sanmathi
Sanmathi

Reputation: 131

It was localhost:9000 itself. I dint try running the server again. Actually the code is not able to identify the routes file which is under conf. I am just trying to replicate whatever is shown in the tutorial but it's not happening!

Upvotes: 2

ali haider
ali haider

Reputation: 20182

Based on the information you provided, you need to use the following URL:

localhost:9000  

not localhost:/9000. The URL above should trigger the index method (inside the Application controller) to be called. Based on the implementation you shared, it will result in the index template to be used to render the view (with a 200 HTTP response). Make sure that you have index.scala.template in the views directory.

Upvotes: -2

Related Questions