Archive for the ‘Ruby on Rails’ Category
Rock and Roll Ruby on Rails ....

Loading ...
Friday, August 8th, 2008
If you want to know what’s new in Rails 2.1 or think that you may have missed a new feature, you should check out the e-book “Ruby on Rails 2.1. What’s new?“.
There are all new features described with an example. It’s quite amazing to see how rails evolves.
btw: did you know that there is finally an i18n patch in edge rails, to be released with rails 2.2? this is a solid foundation for other plugins to build on.
Posted in Ruby on Rails, tools, web 2.0 | No Comments »

Loading ...
Saturday, April 26th, 2008
Just a quick post to let everybody know that i’m switching my erb templates over to HAML. All my css with SASS will follow. These two template engines enhance my productivity a lot. it’s compatible with rails 2.
I must admit that there are still some issues like: No ruby code on multiple lines to format the code properly on very long ruby statements. And: HAML source code highlighting in netbeans plugin is quite old and not updated, but this doesnt stop me from using it.
just checkout the “showdown” on the bottom of the first page to get a feeling of HAML.
Posted in Ruby on Rails | 4 Comments »

Loading ...
Saturday, April 26th, 2008
So now you know how to do nicely rounded div corners without using images or any javascript after reading this post.
But how do we integrate this nicely into our rails app? The following solution might not be perfect but that’s what i’m using and like:
(more…)
Posted in CSS, Ruby on Rails | No Comments »

Loading ...
Wednesday, January 23rd, 2008
Ever heard from Picnik? It allows you editing your images direclty within your browser. Forget Adobe Photoshop :) Picnik has been around for a while now but recently it started to offer its service for the public. for free! I played around a bit and must say that it is amazing .. Use it within PHP, classic ASP, .net, Ruby on Rails or whatever… especially i like the idea of the whole service which works like this…
- Send your images to their service (existing image via URL or encoded as multi-part)
- Then the user modifies the picture (size, colors, rotation, special effects…)
- Picnik sends you the picture back to your server (either an URL where you can download it or directly as multi-part image)
Here comes an example I have built for demonstration… (more…)
Posted in .net, PHP, Ruby on Rails, classic ASP (VBScript), tools | No Comments »

Loading ...
Tuesday, January 22nd, 2008
You know the situation when some users add a couple of whitespaces to the front or/and the end of a value they just entered into your application? Yeah, and in most cases we dont really want those blanks in our data. But on the other hand we can not really blame them because sometimes it just happens by mistake. Just imagine your cat played with the space bar while you quickly went for a coffee. The solution is not to get rid of the cat, … Its rahter an extension. And no not to your cat - small extension to ActiveRecord (more…)
Posted in Ruby on Rails | No Comments »

Loading ...
Thursday, December 20th, 2007
When working with Ruby on Rails on a windows machine you will sometimes need the development console or the interactive ruby console (irb). Actually you need it quite often :) If you do so you’ll discover that special character like the tilde (~) or the {}-brackets are not supported there. Why? I don’t know but let me know if you know the reason. However, to solve this problem just create a file which has the following content:
“\M-[”: “[”
“\M-]”: “]”
“\M-{”: “{”
“\M-}”: “}”
“\M-\\”: “\\”
“\M-|”: “|”
“\M-@”: “@”
“\M-~”: “~”
“\M-?”: “?”
save this to e.g. c:\.inputrc and put the following to your irb.bat (which is usually located in c:\ruby\bin\) straight after the @echo off line:
SET INPUTRC=C:\.inputrc
Now you should be a more happier Rails dev.. At least i am. (I found this information at flip’s blog - Thanks!)
Posted in Ruby on Rails, general stuff | No Comments »

Loading ...
Monday, December 17th, 2007
Today i stumbled across a nice tool called Pastie. Pastie helps you if you want to show some bits of your source code to someone else. e.g. you need some help, advice (or you just want to show off with your code). You paste an excerpt of your code and pastie saves it for under a unique URL. Then you send this URL to the person you want to show the code. The big advantage here is that the syntax is nicely highlighted … very nice for remote troubleshooting! I have created a code snippet for demonstration.

(i’ve used code sections to create more sections.)
Posted in CSS, Javascript, PHP, Ruby on Rails, SQL, tools | 1 Comment »

Loading ...
Wednesday, December 12th, 2007
When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I’ve updated my application from Rails 1.2.5 to 2.0.1 and I was happy to have tests. None of them failed and so I knew that my application is ready to rock with the new Rails 2.0.
However, what I want to write in this article about is how to do bulk testing of each single attribute of your models. Let’s be a bit precise. Say we have a model User which has attributes firstname, lastnameand age. In order to perfectly test the User model we should write tests which …
- ensure that invalid values result in an error for the tested attribute (e.g. age -2 is invalid, so the instance should hold an error for the attribute
age)
- and valid values don’t result in an error for the tested attribute (e.g. age 20 should be fine)
Usually you should test a couple of invalid values and a couple of valid values against each attribute of your model. This can be quite a lot to code. I explain a nice approach how to speed things up and save time for the next family event. (more…)
Posted in Ruby on Rails, Testing | No Comments »

Loading ...
Wednesday, December 5th, 2007
Ruby on Rails ships with a lot of predefined validations for your models. Unfortunately there is no special email validation. Even Rails 2.0 does not ship it (check the ActiveRecord changelog) yet. Because I needed it I had to write my own validates_email method. I know there are a lot of plugins but non of them suits my needs. validates_email does the following:
- checks if email is syntactically correct (using regex)
- checks if the host of the email is supported within the application. This is very important for me because I dont want ppl signing up with one-time emails from e.g. mailinator.com. (can be disabled)
(more…)
Posted in Ruby on Rails | No Comments »

Loading ...
Wednesday, December 5th, 2007
Using XHR within Ruby on Rails is as easy as adding up 1 and 1. We use e.g. the link_to_remote helper and point it to a controllers action. The small problem here is that the XHR actions are all available publicly. So calling the action directly within the browser works as well. I say ’small’ problem because we cannot really prevent calling them directly but we can narrow the access only to XHR calls. We want to achieve that a common request to an XHR will fail. XHR actions will only be available if the request itself is an xhr?.
The solution with a bit of Rubyism: every xhr action needs to be postfixed with _xhr. If a calling request is not an xhr then we redirect the user the home url. For this we add a simple before_filter within our ApplicationController which will check all out actions. Here is the snippet… (more…)
Posted in Ruby on Rails | No Comments »