Describe the bug
When generating a scaffold using the Wheels CLI, the generated controller contains incorrect code for fetching records in actions like show, edit, update, and delete.
Instead of retrieving the record via the model, it directly assigns:
This results in runtime errors because params.post does not contain a model object, and no database lookup is performed.
To Reproduce
Steps to reproduce the behavior:
- Run the scaffold generator:
wheels generate scaffold Post title:string body:text
- Start the application
- Navigate to any of the following actions:
- Observe errors when the controller tries to use post
Generated code (problematic section):
function show() {
post = params.post;
}
function edit() {
post = params.post;
}
function update() {
post = params.post;
if(post.update(params.post)){
redirectTo(route="post", key=post.id);
}
}
function delete() {
post = params.post;
post.delete();
}
Expected behavior
The scaffold should retrieve the record using the model, for example:
post = model("Post").findByKey(params.key);
or equivalent, ensuring:
- A valid model object is returned
- CRUD operations work correctly
Actual behavior
- params.post is treated as the model
- No database lookup occurs
- Causes runtime errors when calling methods like:
- update()
- delete()
- accessing post.id
Desktop
Describe the bug
When generating a scaffold using the Wheels CLI, the generated controller contains incorrect code for fetching records in actions like show, edit, update, and delete.
Instead of retrieving the record via the model, it directly assigns:
This results in runtime errors because params.post does not contain a model object, and no database lookup is performed.
To Reproduce
Steps to reproduce the behavior:
Generated code (problematic section):
Expected behavior
The scaffold should retrieve the record using the model, for example:
or equivalent, ensuring:
Actual behavior
Desktop