Skip to content

Generated scaffold uses params.post instead of model lookup, causing runtime errors #2432

@zainforbjs

Description

@zainforbjs

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:

post = params.post;

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:

  1. Run the scaffold generator:
wheels generate scaffold Post title:string body:text
  1. Start the application
  2. Navigate to any of the following actions:
  • Show
  • Edit
  • Update
  • Delete
  1. 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

  • OS: Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions