1

Customize Your Rake Files

Posted in Ruby on Rails at March 5th, 2007 / 1 Comment »

Rcov is a handy tool to make sure that your tests have at least run every line of code in your application. This is very useful if you have forgotten to write a test for a method, or if inside of a method, you forgot to test a conditional statement. Because I find this handy, I incorporate the rcov plugin in my rails applications.

Running rake test:functionals:rcov, my report shows me a long list of items, some of which I don’t want to see. I don’t want to see the coverage of my models in the report. I should get that report by running rake test:units:rcov. Luckily, the plugin allows for me to set arguments like SHOW_ONLY="app/models". But get this, I’m lazy and I don’t want to type that argument let alone remember it every time I want to run the rcov tests. What to do?

Read the rest of this entry »

0

Firebug and the Console API

Posted in JavaScript at February 9th, 2007 / No Comments »

Among the many Firefox extensions out there, there exists Firebug, and it is good. It is truly an amazing piece of software. There is a CSS viewer, so that when you inspect an element in the DOM, you can view all of the CSS attributes that apply to that element. Not only does it show you the applicable CSS rules, it breaks it down to the styles being used and to the styles which have been overwritten. Very nice. There are many other things it does, but one feature in particular that I don’t think I would want to live witout is the console API.

Read the rest of this entry »

Blocks rock and I couldn’t agree more. The functional programming aspect of ruby has started to interest me more and more. Blocks are used all over the place, with respond_to, collect, returning, and ActionView::Helpers::FormHelper#form_for.

Sometimes, a design requires a little extra markup, perhaps something to get that rounded corner to work or whathave you. Now let’s say this piece of code requires certain classes, a certain kind of structure, including a tile, and has to be used in many places, something like a sidebar piece. Instead of copying and pasting this structure over and over, you can use a helper to make you life easier, and if you combine it with a block, it will just feel even more painless.

Read the rest of this entry »

Well, I am about over it. This site was down for a good portion of the day yesterday, serving up “Application Error” messages. I have not touched my code in one bit or tweaked any setting, and the joker was down. I have even noticed it down when Google tries to index my site, as when I used their webmaster tools, I noticed the response errors

I was reading an article on shared hosting and Application Error and realized that Dreamhost may not be the answer I need.

So what is the answer? Right now, I don’t know. But the comments in the aforementioned article did make suggestions to Rails Playground, Planet Argon, and others. I suppose I will bit the bullet and look towards those services, once I have time after theInspirit gets through alpha.

0

RMagick added to gotAPI

Posted in Software Development at January 11th, 2007 / No Comments »

gotAPI is a nice little resource for searchable documentation for some common programming languages and libraries, like PHP, Ruby, CSS, JavaScript, Protoype and the like. The site does not host the documentation itself, but rather provides an interface to find things on other pages.

What makes this service interesting is that users can help support what gets put on the site. To contribute to their API, you create a simple XML file which lists out all of the classes, properties, members and links to where those elements live.

For a project that I am working on, I required the use of RMagick and then i explored their documentation. The Image class has methods spread across three different pages. So I created the XML document with some curling, awking and other scripting fun and posted it to gotAPI. It was fairly easy and I can find things a little easier now using this site.

I got this tip from Jerry Jackson who told me about storing all of my configuration files, like .bash_profile or .vimrc, in an etc directory inside of my home directory. Once the files are in that directory, you could create a subversion repository; and inside of this repository, put the etc directory in that. Once the files are in a repository, you can check out that repository on any machine. Now you have a way to keep all of your config files easily in sync.

Read the rest of this entry »

Internet Explorer frustrates the living hell out of me. Event though IE 7 is finally out, it doesn’t mean that IE 6 can be ignored. I really look forward to the day when my CSS files aren’t full of unnecessary classes and hacks because the major browser vendors got it right and because everyone has casted away the garbage. Until then, I am still in search of tricks to simplifying my life.

One of these tricks is to make IE pretend like it knows how to use the :hover pseudo-class on all tags.

If you have ever tried to do a suckerfish dropdown, then you have gone through the same thing: excitement as you have learned how to use structural markup to create a dropdown and then frustration as your work has been nullified by IE. The fix involves creating duplicate selectors of those using :hover, but instead of using :hover, replace it with a class name .hover. Making what are essentially duplicates and managing more content doesn’t sit well with me. The other trick to getting suckerfish to work in IE is to use JavaScript. The script will add a class definition to the tag when a user’s mouse if over the element and then removes the class when the users mouse is no longer over it. Since this method uses JavaScript to solve one problem, why not make it solve both?

Read the rest of this entry »

Nobody likes to see exceptions when running an application; it means something went wrong and you should have been on top of it. But with that, often times I find people will write code to prevent exceptions rather than just allowing them to occur and then using it in their favor.

Take this bit of ruby code in a rails controller as an example:

class ArticlesController < ApplicationController
  def show
    @article = Article.find(params[:id])
  end
end

That’s pretty solid, but what happens if someone passes in an ID that does not exist? Well in rails’ production mode, it would return a 404 error.

Makes sense! That article doesn’t exist, so it can’t be found. I have dabbled with a little SEO and usability and just a 404 isn’t cutting it for me. I think we can redirect our user back on a right track. For one, we know the user is trying to read an article, so why not redirect the user to a list of all the articles and give them a little warning?

Read the rest of this entry »

4

DRYing Up respond_to

Posted in Ruby on Rails at November 26th, 2006 / 4 Comments »

Now that that release candidate for rails 1.2 is out, people are going to have even more reasons to use the respond_to method in their controller methods. With that, there may come some unsettling feeling that you’re just repeating yourself over and over again.

def index
  @articles = Article.find(:all)
  respond_to do |format|
    format.html
    format.xml { render :xml => @articles.to_xml }
  end
end

def show
  @article = Article.find(params[:id])
  respond_to do |format|
    format.html
    format.xml { render :xml => @article.to_xml }
  end
end

If we want to use the respond_to, we have to make sure it’s in all of our methods. Wouldn’t it be easier to just do something like this?

def index
  @articles = Article.find(:all)
  format.html
  format.xml { render :xml => @articles.to_xml }
end

Doing it this way, we don’t have to write 2 extra lines per method, and we don’t increase our indentation. While that’s not a huge thing, I still just don’t like to constantly write out those lines when I don’t have to when I think we can build something a little trickier.

Read the rest of this entry »

Expression is Microsoft’s suite of web development tools slated to replace the wonderful application known as Front Page. A quick visit to the site for this tool yields a fairly typical Microsoft webpage.

The “web” edition of this tool makes some hefty claims concerning creating valid xhtml/css based layouts. A normal person would reasonably expect a webpage promoting a tool used for webpage creation would most likely be built with the said tool. This would demonstrate the level of quality, the level of EXCELLENCE made possible by purchasing and using it.

Let’s have a look…

First we use a little browser called Firefox and a plugin called web developer to examine the layout of this page. By turning off CSS rendering we can examine the structure and determine how the creators approached the design process.

We clearly see that the developers of the expression site have chosen to use a table based, transitional approach (tables for the main layout, css to move things around within the columns). Well ok, I would have expected them to show off the “css layout” capabilities of the tool a bit more, but this in and of itself is still an acceptable practice.

With Expression web you can: “Validate your site with Compatibility reporting and use the Accessibility report to verify your site against Section 508 and W3C Content Accessibility Guidelines (WCAG).”

Well ok - let’s do some of that to the Expression Web “features” page and see what we get! (using Firefox’s handy developer tools of course).

WHOA! Did they not even listen to their own marketing garbage? 144 Errors! No DocType? Are you kidding me?

The validation report is littered with opening tags that are never closed, closing tags that were never opened, several tags that are not part of ANY of the w3 HTML specifications, dozens of properties on tags that are also not part of any specification, Don’t believe me - see for yourself

Bravo to our good friends at Microsoft for setting such a great example and leading the masses to a more standards compliant internet! (and for giving web standards geeks something to hate on)