andhapp Random ramblings

Rails mentoring

A great way to learn is by teaching others. Why? Because explaining solutions to others gives you a greater understanding of the problem and the solution itself. I have never had any opportunities to really mentor anyone before. Recently, I signed up to RailsMentors site as a mentor and few weeks after that I actually got a chance to help someone with their Rails issues. It has given me a good understanding of someone else’s approach to Rails and the places where they usually get stuck. It’s not just mentoring, you always find some nice tricks someone has used.

For instance, I helped him set up CanCan in the app and advised about using TDD (with Rspec and Cucumber). In addition, I suggested using faker along with factory_girl to seed the database and helped them with routing issues.

Learning is not just one way. I found this cool way in javascript to load and use a font from his code and it was fun and satisfying helping someone out with their issues. Here’s a proof of my performance.

Quote of the day

Keith Bostic:

Perl – The only language that looks the same before and after RSA encryption.

Apache on Mac

To restart apache on Mac, all you need to do is uncheck(and check) Web Sharing through your System Preferences -> Internet and Network -> Sharing but what it does not tell you is any error messages in the config. Therefore, it would look like that the apache has restarted but the server would still not work. If that is the case, just run:

/usr/sbin/httpd

in the Terminal and it will spit out any errors.

Moving from Dreamhost to Linode

Yes, after 3 years with DreamHost, I have finally moved my blog to a Linode server and it did not go as planned therefore, lack of activity on the blog. I never had any issues with it. It was cheap, gave me easy options to install WordPress and all. But being a programmer, I wanted to get the Server Admin experience under my belt and hence the move to a Linode server. I bought it quite a while ago but since I was in the middle of the DreamHost contract (bought a 3 year one), I left it running on it. Unlike my experience, several bloggers and developers had issues with DreamHost. You can read about it here and here. Let us be honest that it’s good value for money.

It’s not until you have actually moved that you realise the advantages of a hosting service. Things like mail server, I tried postfix and had numerous issues. But, thanks to Google apps standard edition. E-mail works like a charm now. Setting up php with nginx and fast-cgi required a few hours and if you are not a developer or don’t have the ambition to learn these things, DreamHost is your saviour.

If you ever decide to move from DreamHost to Linode, please note that DreamHost offers 60 days grace period for you to pay your bill or move your sites. I did not know it and had to move all the sites in a rush where I could have planned it and since DreamHost does not offer a static IP once you change domain’s nameservers, you can’t even access the MySQL database.

Also, remember one thing, no matter what never install a CentOS linux distro on your Linode. Tell you why in my next post.

Using cucumber-0.9.2 and cucumber-rails-0.3.2 with I18n

I have previously, blogged about using factory_girl with clearance and this post (quite similar to that one) describes the need to use messages (notice, success or failure) in your locale file with cucumber and how to go about using them. Needless to say, this pertains only to the Rails crowd but I guess anyone can set-up their gems or ruby aps to extract similar behaviour. I have been using cucumber with Rails3 and been blogging about my experiences for last couple of weeks.

Imagine, you are writing a feature and you would like to test that the correct flash message gets displayed when something goes wrong or as a notification to the user. In order to make sure, I use the same message across the board I would like to add them to my locale file and read it from there. Instead of having to copy paste them since with cucumber outward-in TDD approach one writes the feature then jumps into write controller and model specs to make the feature pass. Now, in order to achieve that all you gotta do is load the i18n library when the cucumber features are run. So, just add the following to env.rb:

require "i18n"

But, I can’t use the following snippet in my scenarios. How will I use it with cucumber?

I18n.translate :invalid, :scope => [:login, :errors, :messages]

Simple, just use it in your step definitions. Instead of the following scenario:

Scenario: Logging in
  Given I am on sign in page
  When I press "Log in"
  Then I should see error messages

use this scenario:

Scenario: Logging in
  Given I am on sign in page
  When I press "Log in"
  Then I should see error messages

In your step definitions, add a new step for “I should see login failure messages” like this:

Then /^I should see login failure messages$/ do
   Then %{I should see "#{I18n.translate :invalid, :scope => [:login, :errors, :messages]}"}
end

And that’s it. It does sound like a lot of work but it took me under 15 minutes to get it working.