The CRUD module cannot convert the meaningful class name in play framework. For example, if i have a Category model and then make a Categories class in the controller folder to extend CRUD, the Category link will not appear in the admin section. However, if i rename the file into "Categorys", it will work. Is there any solution for this small issue ? Because i used to play with CakePhp and it works pretty good with all the name conventions
According to documentation of CRUD module of Play framework
The controller’s class name has to be the model class name with a final ‘s’.
However, you could use @CRUD.For() annotation to customize naming of CRUD controller individually:
package controllers;
import models.Category;
@CRUD.For(Category.class)
public class Categories extends CRUD {
}
EDIT:
After a quick skimming through source code of CRUD module, I think model naming resolution is around line 260 in {location of play}/modules/crud/app/controllers/CRUD.java(for version 1.2.4):
259 String name = controllerClass.getSimpleName().replace("$", "");
260 name = "models." + name.substring(0, name.length() - 1);
It simply finds model name by looking for the word without the last character of the controller name. (I just tested it, you could even name your CRUD controller as 'Categoryz'. And it works just fine)
So, if you really want to fix this in a 'conventional' way, you could modify line 260 of CRUD.java and utilize some library for singular-plural conversion like Inflector in ModeShape. But in my opinion, using @CRUD.For annotation is just fine and more cost-effective.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With