Archive forMay, 2008

Rails new template file extensions

For some of you that don’t know this yet (don’t be ashamed of yourself, I only heared about it a a few months back), Rails 2 recommends a new file extension for your template file.
At this point, everyone was using template extensions like:

  • .rhtml
  • .rxml
  • .rjs

To unify the template files, the Rails developers have come with a clever solution: chaning the template extensions so that they math up and tell you in what format they are.
By doing this, your new template extensions should look like this:

  • .html.erb
  • .xml.erb
  • .js.rjs

You are probably thinking: “everything looks alike now, except the rjs and haml templates. Why not using .js.erb?

Well, the answer is quite simple.

  • .html.erb -> response format is in HTML,  parsed with ERB
  • .html.haml -> response format in HTML, parsed with HAML
  • .xml.erb -> response format in XML, parsed with ERB
  • .js.rjs -> response format in JavaScript, parsed with RJS

If someone ever came up with a plugin that does the same Javascript actions for some templates. Those templates could be called .js.dudesplugin .

You see now? It all makes sence. Rails is all about convention, so it wouldn’t make sense to make an exception from the naming scheme for RJS templates.

Comments

Rails and foreign keys

There is one plugin that I use in all my projects, and that is the Foreign Key Migrations plugin from RedHill. Defining foreign keys can’t become easier then this. Since as far as I know, Rails migrations don’t set foreign keys in your database, so this is the best solution. It uses SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints.

You can even use it for legacy column names that don’t end with “id”. There is even a generator for creating foreign keys on a database that currently has none, so you can easily start using it even at the end of a project.

You can download the EDGE, 2.0 stable, 1.2 stable or 1.1.6 release, depending on your Rails version. Don’t forget the you need the RedHill on Rails Core .

Comments

Netbeans 6.1 Fast Debugger Bug

Yesterday evening, I installed Netbeans 6.1 since I use Netbeans for my Ruby on Rails development. When developing today, I wanted to use the debugger, but for some reason I couldn’t seem to install the Fast Debugger again. After some research on the Netbeans site, I came accross the answer.

Seems like there is a bug in Netbeans 6.1 that was discovered to late and ended up in the release. It will be fixed in a normal update, for the people that realy need the debugger (I guess every good developer), the fix is easy. Just uninstall the ruby-debug-base gem and install the fast-debugger-ide gem.

Everything is working perfectly now :)

Comments (2)

RESTful programming… but what does it mean?

I realy start to get into the Rails rabbit hole. The last 9 months or so, I’ve been working in some Rails projects for the company I work for during the day. I have learned a lot, but when reading other peoples blog, I still feel like a real Uber n00b. I started last weekend on a new project for Netronix . Since I wan’t this project to be like a future reference for other projects, I started to read a lot upon programming styles in RoR. One term that allways poped up was the REST. I saw it at the beginning when I just started to learn Ruby (and Rails) but never realy payed mutch attention to it. And it wasn’t mentioned even once in all of the Rails books that I read. So why bother.

For some reason, I just wanted to know what REST was. So I started the quest at your friendly neighberhood search engine Google . And yes, you get a lot of good hits, but also a lot of junk. During my quest of knowledge, I stumbled apon a nice PDF called RESTful Rails Development . Its not big, but it explains the whole theory in a playful way.

I could realy advice this light bedtime reading to everyone who has started learning Rails, and is just eager to improve his/her Rails skills.

So this weekend I’ll start on refactoring my project. Hopefully it will pay of soon :) . Maybe RESTful programming will become a second nature :)

Comments (1)

Analising and Unit Testing: A crusial part of development…or not

When I first started programming (started with Turbo Pascal and then Visual Basic), I realy enjoyed programming. It was a whole new world opening up for me. Whenever I needed a piece of software to make my life easier, I just sat down in front of the computer and started programming like crazy. VB was a sequential programming language where you could reuse functions by the use of modules, etc. It was fun to use and you could have a finished application within a few hours.

Then came the new hype, Object Oriented programming. The new hype, a new sherif in town. Offcourse when I started at college, we saw Java. I have to admit I had to get used to the idea of OO programming after being a sequental programmer for years. We also had a class where we learned how to analise our projects and manage them in a professional way. Put that class together with Java, and you had a few hours of sleep (if people even bothered coming to class). It was just so boring, I couldn’t see myself as a programmer. Having to analise everything into detail, and using unit tests to test your application, or even develop by the TDD method (Test Driven Development, witch means writing tests first, program later).

For my internship, I chose for the company AMI Semiconductor (now known as ON Semiconductor).  I had to develop some Testing tools for the Test Methodology Departement. After 4 months of intership, I still didn’t feel like developing. I didn’t have to analise everything (they where very loose on that mather), but Java just didn’t got my mojo running.

Then for some twisted reason, I stumbled into the world of web development. Using PHP, but mostly Ruby (On Rails), I wouldn’t change for anything else. I’m allready working for 8 months as an Information Architect, and I’m starting to realize, that the things they thought us about analising and unit testing wasn’t to let us fall asleep. Lately, I’m starting to realize that it is realy nessessary to have a good analisis before you start a project, and having some Unit tests wouldn’t be that bad.

I have finished a few projects at my day job as an Information Architect, and there are a few things that I would have done differently.  One of them would be to have a clearer view of the project. Not everything was analised, witch has become a real pain in the ass now. The client keeps on asking stuff that realy requires huge changes to the system. And after a few months, I realy want to put this project behind me. Second thing is to take some time to create tests. I start to believe they could realy help me keeping my code clean and bugfree.  Offcourse, that’s not only up to me. Some projects have a tight deadline, and a small budget, so the first things that get cut are analising time and time for unit testing (creating proper tests can take time, so they say…).

I still haven’t created a single test. But I have a new project comming up, witch I’m going to develop for Netronix  (my own company) .  And I can assure you, I will analise everything properly, not loosing the target of sight and even start to develop unit tests. This way,the project just can’t go bad and get sore. I don’t think I’m going to go for TDD (Test Driven Development), becouse I know I don’t have the discipline yet for doing that. But maybe in the future, when I get more experience, I’ll give it a shot.

So how about you other developers, do you take time to create unit tests and analise everything enough so you don’t lose focus on the goal? Maybe you guys can give me some pointers on how to write Unit Tests. I allready read some books, but having some practical advise would help me more out, then some theoretical rules.  My next personal project will be written on the Rails framework (sorry Symfony guys, but I think Rails will fit my needs better this time), so some Rails tips would even be better.

So when I can finish my project in success with a strong bataljon of unit test, I maybe can convince my boss to start creating unit tests for all our projects…well, I guess I’ll have to wait and see

Comments