2011-08-20 89 views
1

试行在游戏教程中的自定义编辑器部分,我创建了路线如下playframework问题的路线:NoRouteFoundException

GET  /admin/myPosts/{id}      Admin.form 
GET  /admin/new        Admin.form 
POST /admin/new        Admin.save 

GET  /admin?        Admin.index 
*  /admin         module:crud 

开创了管理类中的方法

.. 
public static void form() { 
     logger.info("Admin.form()"); 
     render(); 
    }  
    public static void save(String title,String content,String tags) { 
     User author = User.find("byEmail",Security.connected()).first(); 
     logger.info("author="+author.getEmail()); 
     //create a post 
     Post newPost = new Post(author,title,content); 
     logger.info("new post="+newPost.getTitle()+" created"); 
     //set tags 
     String[] tagArray = tags.split("\\s+"); 
     logger.info("tag array="+tagArray.length); 
     for(String tag : tagArray) { 
      logger.info("tag="+tag); 
      if(tag.trim().length() > 0) { 
       newPost.getTags().add(Tag.findOrCreateByName(tag)); 
      }    
     } 
     validation.valid(newPost); 
     if(validation.hasErrors()) { 
      logger.error("error in post"); 
      render("@form", newPost); 
     } 
     newPost.save(); 
     logger.info("new post saved"); 
     logger.info("going to index"); 
     index(); 

    }  
    public static void form(Long id) { 
     if(id!=null) { 
      Post post = Post.findById(id); 
      render(post); 
     } 
     render(); 
    } 
... 

的意见/管理员/index.html是

​​3210

当我点击登录时,包含链接的行???原因

Internal Server Error (500) for request GET /admin? 

No route found (In /app/views/Admin/index.html around line 7) 
No route able to invoke action Admin.form was found. 

play.exceptions.NoRouteFoundException: No route found 
    at play.templates.BaseTemplate.throwException(BaseTemplate.java:80) 
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:237) 
    at play.templates.Template.render(Template.java:26) 
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184) 
    at play.mvc.results.RenderTemplate.<init>(RenderTemplate.java:24) 
    at play.mvc.Controller.renderTemplate(Controller.java:659) 
    at play.mvc.Controller.renderTemplate(Controller.java:639) 
    at play.mvc.Controller.render(Controller.java:694) 
    at controllers.Admin.index(Admin.java:33) 
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543) 
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499) 
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475) 
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470) 
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158) 
    at Invocation.HTTP Request(Play!) 

如何解决这个问题谁能帮是否有在路由路径的顺序有问题的crud and secure模块可按照启动消息

更新: 堆栈跟踪通过发挥出在这里

application error page

我试图改变路由条目顺序file..Put的* /admin path before GET/admin? as below ..Now我摹ETTING一个奇怪的渲染页面

GET  /admin/myPosts/{id}      Admin.form 
GET  /admin/new        Admin.form 
POST /admin/new        Admin.save 

*  /admin         module:crud 
GET  /admin?        Admin.index 

weird page 这是在登录时,鲍勃@ gmail的结束了! 对于网址http://localhost:9000/admin?,页面应显示MyPosts链接为选中..但在这里的评论链接显示为选中。

因此,它必须是与路径文件中的路径顺序问题...特别是那个* /admin? ..有人能告诉我它应该放在哪里吗?

有在routes文件一个小问题(缺少/) 完整路径文件

# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

#import crud routes 

GET  /admin/myPosts/{id}      Admin.form 
GET  /admin/new        Admin.form 
POST /admin/myPosts/{id}      Admin.save 
POST /admin/new        Admin.save 

GET  /admin/?        Admin.index 
*  /admin         module:crud 

# Home page 
GET /          Application.index 

# details of a post 
GET  /posts/{<[0-9]+>id}        Application.showPost 
GET  /captcha        Application.captcha 
GET  /posts/{tag}       Application.taggedWith 
POST /posts/{<[0-9]+>id}/comments     Application.postComment 

# Ignore favicon requests 
GET  /favicon.ico       404 

# Map static resources from the /app/public folder to the /public path 
GET  /public/        staticDir:public 

# Catch all 
# Import Secure routes 
*  /          module:secure 
*  /{controller}/{action}     {controller}.{action} 

管理页面正常显示,当我忽略index.html中

#{list items:posts,as:'post' } 
    <p class="post ${post_parity}"> 
     ${post_index}.<a href="#">${ post.title}</a> 
    </p> 
#{/list} 
<p id="newPost"> 
    <a href="@{Admin.form()}"><span>+</span>write new post</a> 
</p> 
Admin.form(post.id)链接

一旦链接添加

#{list items:posts, as:'post'} 
    <p class="post ${post_parity}"> 
     <a href="@{Admin.form(post.id)}">${post.title}</a> 
    </p> 
#{/list} 

No route able to invoke action Admin.form was found错误信息发生

+1

您的CRUD路由应该接近尾声,因为如果它在开始位置,那么所有其他路由都将不起作用,因为路由文件被读入订购。如果您将CRUD路线置于顶部,则会在找到任何其他/管理路线之前拦截路线。 – Codemwnci

+0

你有你的路线文件中的所有路线吗? – Codemwnci

+0

感谢您的帮助..你的评论帮了我很多 –

回答

0

您确定它是导致问题的路线吗?我刚刚尝试过这种情况,并且无法重新创建错误(尽管不使用CRUD和安全模块),但是由于这些路由稍后在路由文件中出现,因此这些问题不应引起问题。

我认为这可能是下面的代码行造成的问题。

<a href="@{form()}"><span>+</span>write new post</a> 

具体来说,该位@{form()}

我想大概应该读

@{Admin.form()} 
+0

我试过..但错误stacktrace指向另一条线。我用截图更新了问题..我试图改变路径的顺序然后给了我奇怪的结果.. –

+1

你的更新显示了CRUD页面,因为这是在你的'Admin.index'路由之前找到的第一个。我不相信你的问题与路线有关。 – Codemwnci

2

的混乱是因为引起的,在管理类有2形式()方法,一个没有arg,另一个id为arg。无arg方法被置于另一个之前。导致路由器非常混乱。

问题在解决方法form()被替换为通过方法形式(Long id)

+0

您也有路线问题。 /管理/?和/ admin可能直接指向相同的路径(/?表示/是可选的)。更改其中一个名称以避免意外的冲突。 –