Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit a1478bb

Browse files
bpamiriclaude
andcommitted
fix: Display categories and tags on blog edit form
The edit() action used var-scoped variables passed as extra renderView named args, which is non-standard in Wheels. Views access data through the controller's variables scope, but var-scoped variables are local to the function. Refactored edit() to match the create() pattern: removed var from blog, categories, postTypes so they are set in controller scope, and use renderView(template="create") without extra args. Also added val() to arrayFind comparison to prevent type mismatch between query iteration types when marking selected categories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 46dfe91 commit a1478bb

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

app/controllers/web/BlogController.cfc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ component extends="app.Controllers.Controller" {
206206
}
207207

208208
// Get the blog post
209-
var blog = model("Blog").findByKey(key=params.id, include="User,PostStatus");
209+
blog = model("Blog").findByKey(key=params.id, include="User,PostStatus");
210210

211211
// Check if blog exists
212212
if (!isObject(blog)) {
@@ -218,17 +218,16 @@ component extends="app.Controllers.Controller" {
218218
throw("You don't have permission to edit this post", "UnauthorizedAccess");
219219
}
220220

221-
222221
// Get categories and tags for the form
223-
var categories = model("Category").findAll(order="name ASC");
224-
var postTypes = model("PostType").findAll(order="name ASC");
222+
categories = model("Category").findAll(order="name ASC");
223+
postTypes = model("PostType").findAll(order="name ASC");
225224
var blogCategories = model("BlogCategory").findAll(where="blogId = #val(blog.id)#");
226225
var blogTags = model("Tag").findAll(where="blogId = #val(blog.id)#");
227226

228227
// Prepare data for the view
229228
var selectedCategories = [];
230229
for (var cat in blogCategories) {
231-
arrayAppend(selectedCategories, cat.categoryId);
230+
arrayAppend(selectedCategories, val(cat.categoryId));
232231
}
233232

234233
var selectedTags = [];
@@ -239,9 +238,9 @@ component extends="app.Controllers.Controller" {
239238
// Set view variables
240239
blog.categories = selectedCategories;
241240
blog.tags = arrayToList(selectedTags, ",");
241+
isEdit = true;
242242

243-
// Render the edit form with the blog data
244-
renderView(template="create", blog=blog, categories=categories, postTypes=postTypes, isEdit=true);
243+
renderView(template="create");
245244

246245
} catch (any e) {
247246
// Log the error

app/views/web/BlogController/create.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<option value="">Select Categories</option>
3636
<cfif isEdit>
3737
<cfloop query="categories">
38-
<option value="#categories.id#" <cfif arrayFind(blog.categories, categories.id)>selected</cfif>>#categories.name#</option>
38+
<option value="#categories.id#" <cfif arrayFind(blog.categories, val(categories.id))>selected</cfif>>#categories.name#</option>
3939
</cfloop>
4040
<cfelse>
4141
<option value="" disabled>Loading categories...</option>

0 commit comments

Comments
 (0)