Skin Spider : Rating Videos And The First ColdFusion Custom Tag

Posted November 14, 2006 at 8:42 AM by Ben Nadel

Tags: ColdFusion, Skin Spider

To learn all about Skin Spider, click here.

To view the most updated application, click here.

To view the current code base, click here.

As a bell-and-whistle type thing, I wanted to provide a really easy way for users to rate the video clips. I also wanted the rating of the video clip to be known without having to go the "Edit Video" page. To kill both of these birds with one stone, I have created the applications first ColdFusion custom tag, videorating.cfm.

Before we get into that, though, let's talk about the Application Programmer Interface (API) that I have created to rate videos. I am not very experienced in AJAX-type stuff so I am not sure of the best practices for calling the server from the browser. As a first stab, I have set up the api.cfm ColdFusion template. If you take a look at this page, you will see that it checks the Action value in the REQUEST.Attributes object and then performs what ever actions are required.

In our case, we are telling the api.cfm that we want to "rate_video". The api.cfm then params the ID and RATING Attribute values (which are expected in the URL) and uses those to update the video rating via the application's Database Service. This action provides no feedback. There is not true/false flag returned. I have envisioned this page as an AJAX port to the application so at some point it will have to return data, but we will do that when it is required. For video ratings, I have decided that no feedback needs to be provided - even if an error does occur, this is NOT mission critical information and it is not the end of the world if a false-rating is displayed graphically for a single page load.

The custom tag, videorating.cfm, provides an interface for calling this API in a centralized, easily maintainable way. If you look at videorating.cfm, you will see that it merely outputs a paragraph with the video rating scale 0 - 10. For each item (an HTML anchor link) of the rating scale, clicking on it will call the Javascript method SetVideoRating(). That's all this custom tag does.

What's important to realize here is that this ColdFusion custom tag is defined in one place and used in both the search.cfm page and the favorites.cfm page. This means that if the way in which rating a video every changes, all we need to do is change the ColdFusion custom tag and those changes will be propagated to all ColdFusion templates that import and use it. We have now protected the application from this point of variation. Protection from variation is really the goal of all smart programming.

In order for the videorating.cfm ColdFusion custom tag to work, it requires the Javascript method SetVideoRating(). This is our first Javascript method. To define it, I have created a custom.js Javascript file and linked to it in the application's standard header, _header_standard.cfm. If you take a look at the code, you will see that the Javascript method just loops over the links in the rating module, turns them all off, and then turns on the one that the user clicked. This is just the visual representation. To make sure that the Database lines up with what the user is seeing, this method then pings the API (api.cfm) requesting that the video rating be set.

This was a place that I was planning to use AJAX, but I have decided that it would have been overkill. AJAX is very cool, but it does have overhead and it is a little complicated. We want to keep things as simple as possible for as long as possible. To that affect, I have decided that pinging the api.cfm using an Image.src hack is much easier and faster than dealing with an AJAX request. And, in the end, since we are not providing any feedback for this call, it accomplishes the same exact outcome.

This ColdFusion custom tag is imported for use on both the search.cfm and the favorites.cfm pages. Taking a look at the code, you can see that the custom tag is imported with a prefix at the top of the template and then used later down. Remember, when using CFImport, each template that uses that custom tag must have its own CFImport statement. This might make it seem like using CFImport over using the old school "CF_" notation makes it harder to use, but, in fact, CFImport is a smarter choice. I don't want to get into it now, but CFImport allows us to provide a path to the desired tags and makes logic grouping possible. In the long run, it's much more powerful that "CF_" or CFModule.



Reader Comments

There are no comments posted for this web log entry.

Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »