Ruby 1.9 and Rails 3 Changes

The following are some changes I recently came across when updating a rails 2.x plugin to 3.x.

 

  1. Default HTML Encoding or Escaping behavior has changed (XSS prevention).  Now, in order to not have your <>'s encoded, you can use <%= raw ... %> or "<div>".safe_html

  2. Time.parse will return 

 

The full-text query parameter for fulltext query string is not valid

I started receiving the error the full-text query parameter for fulltext query string is not valid after upgrading to .NET 4 when calling a function in SQL Server 2008 from Linq to SQL.   It seems LTS is sending the string as nvarchar(4000) event though I had defined the paramater to the function with a length of nvarchar(200).

The work around that I put in place as we define the parameter to my function as 4000.  Not ideal, but it resolved the error.

NoClassDefFoundError Could not find the main class

A common question that programmers new to Java have is what is the relationship between packages, javac, java, and the NoClassDefFoundError.

It is important to understand that there is a relationship between the package and physical directory structure.  For example, if you have a class "MyClass" and it is in a package com.myapp, you would want the following file structure

MyProject
   |--source
      |--com
          |--myapp
              |--MyClass.java
   |--classes

MyClass.java would have package com.myapp; at the top of the file.  Then from the source directory, you could issue the following to compile and place the class file in MyProject/classes/com/myapp/MyClass.class

javac -d ../classes com.myapp.MyClass.java

The result would be that the compiler would create the directories under /classes (note classes needs to exist).  Now, to run MyClass, issue the following from the classes directory:

java com.myapp.MyClass

It is important to realize that when compiling and running that the package name, fully qualified class name, and location you issue javac and java from are all important.

 

 

uploadify showing an error

Uploadify is an excellent upload plugin script.  One issue that I recently encountered was how to notify uploadify that an error occured with your server side scipt while processing a file.  I found that by returning a status code of 405, uploadify will mark the file as errored (highlight in red in the queue).

To accomplish this, you should set the status code to 405 with your response from your server side code.  The below example show how to do this in C#, the the same applies for any server side language (php, ruby, etc).

I have placed this in a finally block and check a local variable response and set the status code if the value is not success.

 finally
        {
            if (response != returnValueSuccess)

            {
                context.Response.StatusCode = 405;
            }
            context.Response.Write(response);
        }
}

 

SQL Server 2008 slow query on fulltext indexed column

Experienced a very strang issue with a query after upgrading to SQL Server 2008 from 2005.  A query that took less than one second on SQL 2005 ended up taking 27 seconds on SQL Server 2008. 

Exact scenario:

Query that selects data and one of the columns in the select list belonged to a full text index.  If this column is not in the select list, the query runs in under one second.
Removing the full text index did not make a difference
Changing the data type from nvarchar(max) to nvarchar(3000) did not make a difference
adding a where filter of column != '' worked

Not sure why this happened and only in SQL 2008 but not in 2005 but if you are seeing the same issue, I hope this article helps.

LINQ to SQL dynamically set order by

Often I find the need to dynamically specify the order by for a LINQ to SQL query.  I came across a very nice example of this here

I needed to use this technique with a CSLA class, so I needed to call it in a sligthly different manner than the way explained in the article.  I was grouping information and needed to then dynamically set the order by and finally place the results into a CSLA read only list.

I accomplished this as follows:

  1. First I specified my LINQ query and selected the results into an annonymous type and placed into a variable (var data = ...)
  2. Next, called my OrderBy extension method on the LINQ query created in #1

    var ordered = data.OrderBy(criteria.OrderByProperty, criteria.OrderByDesc);


    The criteria object is the typical pattern used in CSLA to pass data to your data access methods such as fetch.
  3. Finally, I selected the data elements into my CSLA list item, and add to the parent list object

    var selected = ordered.Select(a => MyCslaListItem.GetMyCslaListItem(a.Id, a.Name, a.Email, ...));
    this.AddRange(selected);

I understand I could do this in fewer steps, but am leaving as it to explicitly outline the approach taken.

 

 

Generating a valid RSS feed using SyndicationFeed and Rss20FeedFormatter

If you are using the .NET Rss20FeedFormatter and SyndicationFeed classes to generate an RSS feed, you may run into an issue of needing to include a link attribute to the channel element.  If you validate the default RSS generated the validation will fail since the channel element does not contain a link attribute.

You can test this by going to http://beta.feedvalidator.org and entering your feed Url.  If you recieve the error

Missing channel element: link

you can modify your code as follows:

 

SyndicationFeed syndicationFeed = new SyndicationFeed(synicationItems);
syndicationFeed.AttributeExtensions.Add(new XmlQualifiedName("link"), "http://yoursite.com");

 

This will produce a valid RSS feed with a channel that contains a link attribute.

ASP.NET MVC strongly typed view error Could not load type

I have been doing some work on a asp.net webforms website that has been "upgraded" to also include the mvc bits.  One issue I ran into was an error when trying to create a strongly typed view.  I was receiving the below exception:

Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<MyViewModel>'.

I also was not getting intellisense in my View page when trying to access the Model property.

It sounds like this relates to dll references, and I found the solution at the below link.  

What I did to resolve was to create a new MVC project and then copy the web.config from the Views directory to my older webforms website.  That did the trick...

http://forums.asp.net/p/1378448/2908692.aspx