Further explanation of "Using a AddRuleViolations Helper Method" from Nerd Dinner (ASP.NET MVC 2 Tutorial)

Recently I started investigating ASP.NET MVC 2. I do not have any
previous experience programming on the MS stack and, honestly, I was
quite skeptical that I would enjoy any MS tool as much as I love Ruby
on Rails (which I have been using a lot over the past year). To my
surprise, ASP.NET MVC 2 is actually quite nice and I have enjoyed
working through the initial tutorial that I found. The tutorial is
extremely well laid out, informative, and easy to follow especially
since I already know the MVC ideas from Rails. The tutorial is called
Nerd Dinner and can be found here: , called Nerd Dinner and is found
here

The main point of this post is to explain in more detail one section
of the tutorial that took me a while to figure out. This is more a
reminder/explanation for myself, but I hope that others will find it
useful as well.

Issue - Where to place the code?

In step 5 of the tutorial there is a section titled "Using a
AddRuleViolations Helper Method" which did not contain enough detail
for me to implement on my first attempt. Excerpt from step 5:

We can make this code a little cleaner by adding a
"ControllerHelpers" class to the NerdDinner project, and implement an
"AddRuleViolations" extension method within it that adds a helper
method to the ASP.NET MVC ModelStateDictionary class.   This extension
method can encapsulate the logic necessary to populate the
ModelStateDictionary with a list of RuleViolation errors:


The basic idea is for all of the RuleViolations to be detected and
stored only in the Model. The Model knows about the business logic,
detects violations, and stores them. The controller pulls the list of
violations directly from the Model and passes the list to the View.
The View blindly renders the violations from the list by displaying their title and
error message. We can change/add/delete our rules at any time without
changing a single line of code in the View or Controller.

Sounds awesome.Problem is, I could not understand where to create this
Helper method in the project and get everything to work nicely.

Solution - Look at the final source.

My google-fu was weak on this one and after reading over many
semi-related blogs posts/stackoverflow threads I realized that I
should just look at the code for the final product. Nerd Dinner has
all of the production code available here. It
was easy to find the solution and understand how everything worked. I
will outline everything below:

1) Move the class definition for RuleViolation from inside the Models - > Dinner.cs partial class to its own class called RuleViolation.cs inside the Models directoy.
2) Create a Helpers directory at the same level as the Models directory.
3) Create a ControllersHelpers.cs class in Helpers directory and place the code from
step 5 in the tutorial in there. Note: Make sure that you include 'using
NerdDinner.Models' inside your ControllersHelpers class so that it
knows about the RuleViolations class definition. I also had to throw
in a 'using System.Web.Mvc' so the ModelStateDictionary could be
found.

public static class ControllerHelpers {

03. 
04.   public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> errors) {
05.    
06.       foreach (RuleViolation issue in errors) {
07.           modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
08.       }
09.   }
10.}


4) Add 'using NerdDinner.Helpers' to DinnersController so that the
controller knows where to find the definition of our new
AddRuleViolations() function
5) test (celebrate if it works, cry if it doesn't)


Okay, that's it. Typing this out helped me cement my understanding and
I am sure that I will be back to check how I did this down the road at
some point. I hope you found it useful.

Dining Hall Survey - Current Implementation and Possible Improvements

Each semester, the University of Delaware's Dining Services sends out a survey to the entire University community. This survey serves to collect large amounts of data from the students over a three week period. It directly impacts Dining Service's future operational enhancements made on campus. This post will highlight both the positive and negative aspects of this survey, as well as discuss how Napkin Board could potentially enhance the success of obtaining feedback from the student population.

Full disclosure

I am not associated with UD Dining Services or Aramark in any way. I am a senior at the University of Delaware and the lead developer for Napkin Board (www.napkinboard.com), a website that aims to improve student dining on campus by providing simple methods for students to provide and view daily feedback on their dining experiences.

Take the survey!
As an active member of the UD student community, I encourage anyone who reads this post to take the Dining Services’ surveys when prompted. The data collected directly impacts future changes to current on-campus dining. Without direct feedback, Dining Services can only make educated guesses as to which changes are necessary and/or relevant. Now is your chance to speak up!

Points of Interest:
Prizes Rock - Offer an incentive to increase participation

Any community member who fills out the survey can enter to win a $250 Best Buy gift card or one of two (2) $25 Best Buy gift cards. This approach is a great motivator for getting survey responses; all college students love free stuff and $250 isn't chump change. However, many students will not view the small chance (as low as 1/22,000 total undergraduates, graduates, faculty, and staff at UD) to win a prize as worthy of their precious time and could opt not to complete the survey.

Students will be more likely to participate if they can work towards guaranteed rewards. Napkin Board is currently exploring options which will provide incentives for participating students, such as gift certificates, in exchange for their feedback.

Once a semester is not enough
Dining Services needs community feedback on a daily basis, not once a semester. Anything less frequent is ineffective for several reasons. First, people are forgetful. A student with a comment for Dining Services in February will most likely forget the details of that comment by the time the biannual survey becomes available. Second, because most comments will generally lack detail, a biannual survey will most likely only provide a high level picture of general dining trends. Although these general trends are extremely important, situational details are critically important when analyzing negative trends and working to improve them. The daily feedback that we hope to provide with Napkin Board can easily supplement the Dining Services’ current surveys with those necessary fine-grain details.

The Survey is too long
The community email estimates that the survey takes five minutes to complete, however, the main page of the survey estimates up to twice that time length and it took me longer than even that estimation to complete the survey. The problem with a long survey is twofold: people are busy and their attention spans are short. After ten minutes of clicking buttons rating dining halls, boredom sets in. Some students might choose to "click through" the questions in order to finish faster. "Clicking through" skews statistics, thus providing less meaningful data.

Napkin Board’s surveys are very time-conscious; students can provide feedback in less than 30 seconds on the current website. Ideally, this lower time commitment will lead to short, accurate, and frequent feedback postings from students. Students will also be more inclined to provide feedback the easier it is. Napkin Board plans to integrate with Facebook, create iPhone and Anroid apps, and allow students to use regular SMS text messages to provide feedback.

Conclusion
Surveying students is an extremely good idea and I am glad that UD asks for feedback. I wish that it happened more often and that there was less of a time commitment for the student population. I have already addressed the benefits that Napkin Board could provide (with its shorter survey formats and daily feedback features) and hope that we have a chance to work with the University of Delaware to improve the overall student dining experience.

I look forward to your feedback in the comments.

Sorting and filtering HTML tables

One main feature of Napkin Board (www.napkinboard.com) is displaying
the menus for dining halls in an easy to read format. I think that the
easiest way to do this is to show the current day's menu in a table,
which can easily show the name and category of food items. However,
plain old HTML tables force the user to spend time scanning the table
to find what they want (and are boring). Allowing the user to filter
the table based on a keyword and sort columns would be a vast
improvement.

I found some great javascript libraries and scripts to help me
accomplish just that.

Sorting HTML Table By Columns

The user can click the heading of a column and the entire table is
sorted according to that column. The header of the sorted column is
highlighted and displays an up/down arrow to indicate which order the
data is sorted (ascending/descending). As expected, clicking the
column a second time will sort the data in reverse order and change
the up/down arrow.

In order to accomplish this, I use a javascript library that I found
called TableKit. It leverages the Prototype Javascript Framework in
addition to some custom code.

This is a code snippet of how it works:

<table id="menu_table_194" class="sortable">
  <tr>
    <th class="food_item_name_col text">Name</th>
    <th class="food_item_category_col sortfirstasc text">Category</th>
    <th class="food_item_avg_col number>Avg</th>
    <th class="nosort">Rating<br />form</th>
  </tr>
</table>

I can use class names to tell TableKit how to handle
sorting the html table.

-nosort: tell TableKit that a certain column should not be sortable
-sortfirstasc: tell TableKit that this column is the default and
should be sorted ascending when the page loads
-number,text: tell TableKit the data type of the column explicitly. If
not specified, TableKit attempts to guess the data type by looking at
the first cell in the column.

Filtering HTML Table

The user can type a keyword into a box and the HTML table will only
show rows that match the keyword. After a quick Google search I found
a javascript function written by Tobi(?) here.

His function loops grabs the table from the DOM by id. Then, it loops over the rows of the table and sets the display of non-matching rows to 'none'. I call his function once for each HTML table on the page (one table per menu shown). This is how I present it to the user:

<form class="inline">
 <input name="table_filter" onkeyup="filter_tables(this, <%= id_array %>)" type="text">
</form>

Benefits and Downsides

Benefit (big): work done client-site = more efficient

All of the menu data will remain the same as the user interacts with it so there is no point in asking the server for that same data again. Instead, all of the menu data is provided to the browser once on page load and then javascript can manipulate how it is presented as much as it wants.

Downside (small): some browsers handle javascript a bit differently

In Chrome, both sorting and filtering work fine for columns containing text and numbers. However, in Firefox, the column with numbers will not sort unless each cell in the column contains a number. For example, if no average rating exists for a food item, then I would like to display nothing. Instead, Firefox requires me to show a zero in order for the sorting to work for that column.

Downside (fixable): javascript functions not playing nicely = more work required from me

The TableKit functions provide the sorting capabilities while the function from Tobi's site provides filtering capabilities. They were not intended to work smoothly together and there is one bug that I have to fix. After a sort, TableKit automatically "stripes" the table by highlighting every other row (eg green row, red row, green row, red row, etc). However, Tobi's function does not take this into account and the row colors do not change appropriately after the table is filtered (eg, green row, green row, red row, green row). I will have to tackle this visual bug myself.

Napkin Board gets college news coverage!

It has been a long time since I have last written a post. I have spent all winter teaching myself a new web framework, Ruby on Rails, and working on Napkin Board (www.napkinboard.com), which is my new project (and obsession). Napkin Board is a website designed to improve the student dining experience on campus by allowing students to access straight-forward menus of dining hall meals, rate the food that they eat in the dining halls, and view other students' ratings of each food item. I am happy to announce that Napkin Board got a write up in the UD Review today. I contacted the Review to let them know about the site and see if they would be willing to talk to me about it. After meeting with a reporter, they published the article today. Here is a direct link: New web site allows students to rate dining hall food. I hope that the article sparks some student interest and directs some traffic to the site. Getting the first group of users will be difficult, but hopefully they will love Napkin Board and spread the word to their friends. As I read the article, I saw a few things that I would like to clarify and I had a few additional thoughts.
  1. I am a senior computer science major at the University of Delaware (not a junior as the article states).
  2. I was an active member of the Student Dining Committee during my sophomore year. We met with several administrators from dining services, including Debbie Miller, on a monthly basis to give suggestions and feedback. There were more than 3 students on the committee, but I never saw more than 5 or 6 at any single meeting and I attended all of them.
  3. I have not had a dining hall plan since my sophomore year (2008).
  4. One of the main features of Napkin Board is getting user feedback from students. That feature has been up and running from our first launch.
  5. I reached out to Ryan Boyer (Director of Marketing for Dining Services at UD) and Michele Kane (Associate Director of Residence Life at UD) to personally introduce myself and talk about the possibility of working with the University to improve student feedback by using Napkin Board.
Well, those are just a few points I wanted to make public. I look forward to improving Napkin Board based on student feedback! Let me know what you think in the comments.

Crazy Error with RoR, Heroku and old app files

I was working on using restful_authentication and role_requirement for my rails app. Everything was working on my local system so I pushed to heroku and once I tried to log in as a user I got a 'access denied' message. This message appears when a user doesn't have admin role to access a page. This was totally bogus because my user has admin access to everything. I tried all of the following with no success: 1) checked the users and their roles through the console. 2) restarted the servers 3) remigrated the db 4) read the logs 5) destroyed the app and started from scratch Nothing seemed to be working and I was really getting annoyed. Then, in the log files I noticed that it was using a controller called user_controller_old.rb. That was code from before I added role_requirements that I wanted to hand on to. No where in my code was it using that controller and it was working perfectly on my local system. Heroku was being crazy. Once I deleted all of the user_old* files from the app directories and repushed to Heroku everything magically worked again. I am way too tired to figure out what the heck just happened. 2 hours I will never get back. Bummer.

Napkin Board & Ruby on Rails

So I just finished my busiest semester of all time at UD and I have some time to myself. I have decided to take the entire winter break (7 weeks over the holidays) to develop the site that I have been dreaming about for months. I am going to do it in RoR because I want to learn a new language and I hear great things about it. I read Hacker News daily and I found this helpful book that is free as a PDF. It is not complete yet, but I found it very helpful while getting started. Step 1 - Install everything I wish that installing everything was not difficult, but I always seem to run into problems when undertaking installs. I met several while trying to get my Ruby on Rails environment up and running. Problems: - Installing ruby and rails took a few tries. I am developing on Ubuntu 9.10 and this post was extremely helpful to get started. - I ran into trouble installing the sqlite3 DB that the book recommends. This post solved my problems perfectly. - I was pulling my hair out for a while trying to figure out why rubygems was not working as intended. Turns out that the gem path to the executables was not in my system path. Once I edited ~/.bashrc by adding the line 'export PATH=$PATH:/var/lib/gems/1.8/bin' all of the installed gems worked as expected. - I quickly got fed up with using xemacs so I installed the RadRails plug-in for eclipse. Much better.

The Beginning

My name is Conor Gilsenan and I am in my senior year of a Bachelor of Science in Computer Science at the University of Delaware. I began working with web technologies last year in an Advanced Web Tech course here at UD and instantly knew that programming for the web was something that I really enjoyed. During my sophomore year, I discovered Paul Graham's essays here and instantly realized that I wanted to create my own company. With these two ideas put together, I am working towards eventually starting my own web 2.0 company.

I attended Startup Bootcamp 2009 at MIT and heard a talk given by Dharmesh Shah. His talk was amazingly inspiring and will definitely stay in my mind for a long time. He suggested starting a blog in order to gain users and have a way to express thoughts and gain a following. So, in following with his advice, I will publish to this blog and hopefully it will be the beginning of something great

Definitely check out the video clips from justin.tv here.