Why Ruby on Rails is better than .NET

JUL

10

2006

2 comments

For the past four days at work I've been assigned to apply a redesign to an older .NET site that we did a couple of years ago. It has been infuriatingly frustrating trying to apply a CSS-based design to a table-based .NET site. The way .NET handles almost everything is so convoluted and esoteric that it took me a full day just to get the hang of how it handled displaying markup.

And what is the deal with the datagrid?!?! It's great on paper, but crap in practice. Just the datagrid definition spanned five lines. Using the AlternatingItemStyle tag to get alternating styles for the table rows is ok, but Rails makes it SOOOO much easier with the cycle method. And speaking of styles, the datagrid has to have each style that you'd like applied declared seperately which makes for the huge datagrid definition. Also, take a look at the HTML that a datagrid produces. You'll be surprised at how much markup it can create for a simple <td>.

Now, don't get me wrong. I can see where .NET would be useful and I'm sure there are a ton of examples where it would make much more sense to use .NET than Rails. I think my biggest problem is that I know almost nothing about .NET. I can get by with making visual changes, but I stay far away from the codebehinds.

Closing thoughts: give Ruby on Rails a try! You might just like it!

Tagged: rails

Lightbox JS 2 hacked for AJAX

JUN

23

2006

3 comments

At work today I was given the task of implementing Lightbox JS v2.0 on our new website. To its credit, it was extremely easy to get working... almost too easy.

Of course, that's when I encountered a problem. On our portfolio detail page, Shawn put in a neat little AJAX slider for viewing the pictures of each project. The problem arose because the pictures were being generated dynamically after the page had been loaded. For the Lightbox to work, it needed to know about all of the images as the page loaded. Any images generated after that wouldn't work correctly.

I looked around for awhile to see if I could find anyone else who had run into this same problem that maybe had found a workaround. Well, I found several people who were having the same problem, but no one had solved it yet. So, against all odds, I started poking around in the code to see if I could maybe get something working. Below is my step-by-step solution.

First of all, I edited the .js file. Take the following chunk OUT of the file. Delete it, comment it out, whatever. The code is located in the start: function(imageLink) block.

// if image is NOT part of a set..
if((imageLink.getAttribute('rel') == 'lightbox')){
  // add single image to imageArray
  imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));			
} else {
  // if image is part of a set..
  // loop through anchors, find other images in set, and add them to ImageArray
  for (var i=0; i<anchors.length; i++){
    var anchor = anchors[i];
    if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
      imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
    }
  }
  imageArray.removeDuplicates();
  while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
}

Notice: This breaks the ability to add images to a set and cycle through them from within the Lightbox.

The next step is to initialize the myLightbox object. Put the following code at the top of the page that you'd like to use the Lightbox (or alternately, you can just call it in the <head> section).

<script type="text/javascript">
  initLightbox();
</script>

Update: IE will throw an error if you put the above line of code in the middle of a page. The page must load fully before it will successfully evaluate the JavaScript. So, just put the call at the end of all your code.

And last, all we need to do is to call the start() function to make the magic happen. I'm using Rails, so this is how I did it:

<%= link_to_function image_tag('/images/thumbnail.jpg'), "myLightbox.start('/images/fullsize_picture.jpg');" %>

And just substitute /images/fullsize_picture.jpg with the actual path to your image.

I hope this can help someone else out.

Tagged: javascript, lightbox, ajax

Syndicated!

JUN

16

2006

0 comments

One of the things I had hoped to be able to do with Rails for this blog was to create an RSS feed. I briefly looked at the chapter that describes how to do this in the Rails Recipes book and kinda decided put it off until later.

Well, after seeing that Adam added an RSS feed to his blog and even provided the steps he took to accomplish it, I decided to finally implement it. It turned out to be a lot easier than I thought.

So, if you're really bored often, go ahead and subscribe.

Tagged: rails, rss

Ruby on Rails having problems with table column names

JUN

15

2006

1 comment

I was working on a project for work today that invloved the client be able to enter customer testimonials into a database to be displayed randomly on each site page. I named the table quotes and it had three columns: id, person, and quote. I made id an integer and quote and person were both varchars. Everything worked fine with this configuration.

After some testing, I discovered that a varchar wasn't the best type for the quote because it didn't have enough room for the longer testimonials. Like a good Rails developer, I wrote a migration script to change the quote column to be text instead of varchar. Well, after making this change, Rails bombed every time I tried to add another quote. For some reason, it didn't like the column to be of type text and have the same name as the Rails table object. I'm not exactly sure what or why specifically caused this problem, but it definitely didn't work. After some consultation with The Shawnami, the resident Rails guru, and some extensive frustration, we finally decided to try and just rename the column. Guess what? It worked perfectly after I renamed it content.

Tagged: rails, db

Safari line height problem

JUN

14

2006

2 comments

It seems like I've been stuck on the line-height property lately. Well, today I noticed Safari giving weird behavior with regards to line-height. In the CSS documents we create at work, we always include a standard set of entity styles at the top and then go back and edit them if needed. Well, in that standard set is where we define the font-size, line-height, padding, etc. for our most-used html tags. I ran into a problem today where Safari was effectively ignoring the previously declared line-height property when I redefined the font-size of an element. So, to fix this, I had to re-define the exact same line-height(in percentage) for the new font-size.

I'm a huge fan of the Mac (I use one at work), but Safari can cause some headaches (nowhere near IE, though).

Tagged: safari, css, xhtml


© 2010 Travis Roberts. All rights reserved.