Why am I not able to override CRUD template when using @CRUD.For?
I'm reading the play tutorial and to spice things up a little bit I decided to use @CRUD.For instead of using the default model na开发者_开发百科me pluralized. The problem is that I'm trying to override the template of that model and, using @CRUD.For, it just doesn't seem to work. However, when I use the default name it just works...
I have:
1) Model in app/models/Comment 2) Admin class extending CRUD annotated with @CRUD.For(Comment.class) app/controllers/admin/AdminComments 3) I have the file app/views/AdminComments/list 4) I'm using the command: play crud:ov --template AdminComments/listThen I check the admin area and nothing... As I said, when I use the default name Comments it works.
Thanks in advance.
From reading the information on CRUD.For
on the play documentation, I can't see that you are doing anything wrong. I assume that when you say you have the file app/views/AdminComments/list
you actually mean app/views/AdminComments/list.html
, if not then that is likely to be your problem.
Also, you have stated that you use play crud:ov --template
, leaving this last in your list. This command creates a new file in your views area, based on the template, so that you may override it to work the way you wish. I would suggest going through it in the right order, which is
- Create your model class
- Create your CRUD class, with the CRUD.For annotation. Making sure you import
models.Comment
- run play command
play crud:ov --template AdminComments/list
- Edit the generated template, in
app/views/AdminComments/list.html
- Make sure AdminComments.java is inside
app/controllers
and that your list.thml is inapp/views/AdminComments
Your AdminComments class is inside a sub-package admin
(controllers.admin
) and not directly inside the controllers package. So you will have to create a folder named admin
inside your views directory and move the generated file app/views/AdminComments/list.html
into this directory. Now the file path will be app/views/admin/AdminComments/list.html
.
This worked for me. However the crud:ov command should handle this by itself.
精彩评论