3

Railsを使用すると、他のリソースの論理的な子であるリソースをURLにマッピングできます。

/magazines/:magazine_id/ads/:id show    display a specific ad belonging to a specific magazine

In Playでこれを行うことは可能ですか?

4

2 に答える 2

7

Playは、引数が何らかの関係を表すかどうかを気にしません。それはコントローラーの仕事です。

もちろん、それを行うことは可能です:

GET /some/:parent/:child   controllers.Application.getRelated(parent: Long, child: Long)

コントローラー内:

public static Result getRelated(Long parent, Long child) {
    return ok(SomeFinder(parent,child));
}
于 2012-06-26T12:53:23.787 に答える
2

はい、それは可能です。ルートファイルでは次のようになります。

GET   /magazines/:magazine_id/ads/:id/show   controllers.MyController.show(magazine_id: Long, id: Long)  

そしてあなたのコントローラーで

public static Result show(Long magazine_id, Long id) {
    ...
}
于 2012-06-26T12:51:08.853 に答える