Skip to content

Instantly share code, notes, and snippets.

@mhenke
Created August 20, 2010 13:01
Show Gist options
  • Save mhenke/540248 to your computer and use it in GitHub Desktop.
Save mhenke/540248 to your computer and use it in GitHub Desktop.
<h1>Editing entry</h1>
<cfoutput>
#errorMessagesFor("entry")#
#startFormTag(action="update", key=params.key)#
#textField(objectName='entry', property='userID', label='User I D')#
#textField(objectName='entry', property='categoryID', label='Category I D')#
#textField(objectName='entry', property='title', label='Title')#
#textField(objectName='entry', property='body', label='Body')#
#dateTimeSelect(objectName='entry', property='dateCreated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Created')#
#dateTimeSelect(objectName='entry', property='dateLastUpdated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Last Updated')#
#submitTag()#
#endFormTag()#
#linkTo(text="Return to the listing", action="index")#
</cfoutput>
<cfcomponent extends="Controller" output="false">
# ...
<cffunction name="show">
<!--- Find the record --->
<cfset entry = model("Entry").findByKey(params.key)>
# ...
</cffunction>
<cffunction name="edit">
<!--- Find the record --->
<cfset entry = model("Entry").findByKey(params.key)>
# ...
</cffunction>
<cffunction name="update">
<cfset entry = model("Entry").findByKey(params.key)>
# ...
</cffunction>
<cffunction name="delete">
<cfset entry = model("Entry").findByKey(params.key)>
# ...
</cffunction>
</cfcomponent>
<h1>Create new entry</h1>
<cfoutput>
#errorMessagesFor("entry")#
#startFormTag(action="create")#
#textField(objectName='entry', property='userID', label='User I D')#
#textField(objectName='entry', property='categoryID', label='Category I D')#
#textField(objectName='entry', property='title', label='Title')#
#textField(objectName='entry', property='body', label='Body')#
#dateTimeSelect(objectName='entry', property='dateCreated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Created')#
#dateTimeSelect(objectName='entry', property='dateLastUpdated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Last Updated')#
#submitTag()#
#endFormTag()#
#linkTo(text="Return to the listing", action="index")#
</cfoutput>
@raulriera
Copy link

Duplication in this case is more important than DRY. These templates are meant to display a barebone CRUD, while there is duplication, it can't be a crud if actions are missing (or "hidden" while using techniques to DRY up the code)

The templates are the exact same as Rails (back then, I don't know how they handle Scaffolding now), but the simplest the better, it is easier to "grasp" them as it is.

@raulriera
Copy link

Btw you are commenting out the difference between the actions ;) I could make any code duplicated if I remove the differences :P

@mhenke
Copy link
Author

mhenke commented Aug 20, 2010

Thanks, I'll add your justification to the article. Maybe you want to add that to the description so people if curious why all the duplication. They will understand why this isn't meant to be a final completely polished code generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment