Ruby on Rails
This Category displays all articles in my blog relating to Ruby on Rails (RoR) application development.
Hit a wall?? step away from your keyboard
I know a lot of people are already thinking what the hell is this man talking about?
Well recently while working on some tests for an application I've been working on, I found that I had hit a brick wall, in terms of I had to write some tests to ensure that some existing code worked as we intended however none of the tests I had written seemed to test this in the right way, after a while of re-writing said tests and re-writing them again, I finally decided to leave it and move onto something else. In doing this it gave my brain a break from thinking about the problem in hand and as a result when I came back to these tests I realised where I was going wrong and so write the tests which worked and not only that helped me to re-factor the code I was testing.
So my snippet of advice for anyone in a similar situation, if you feel like you're banging your head against a brick wall, don't get bogged down by the problem and let it impede your progress, take a break from it and come back to the problem later.
How to: getting a rails 3 beta project set up with Rspec and Cucumber
How to: get a rails 3 beta project set up with Rspec and Cucumberokay so I recently started my first Rails 3 project I knew there was probably going to be one or two issues getting up and running and one of the main issues I found was getting Rspec and Cucumber to play ball with rails 3, but never fear here is how I got everything working.
Step 1: Installing Rails 3 and setting up a new app
I'm not going to go into detail on this step purely because I think that if you can't improve on something then don't try, so for this step I used Ryan Bates' Railscasts on getting started with RVM and Rails 3 Beta which can be found here to get me up and running, For reference I am still using Ruby 1.8.7 for this tutorial and the app I'm building I have called "test_app".
Step 2: Setting up your test environment in your Gemfile
Once I'd done a bit of reading this was actually quite simple, all you need to do as Rails 3 uses bundler as standard is open the Gemfile for your app in TextMate if you are using Mac OSX or any other text editor of your choice and add the following:
Step 3: its bundling time!
In your terminal window first cd into your application in my case this is:
Now if we go and try writing some Cucumber Stories/features and try running them we can see that they work, if you are new to Cucumber I found that once again Ryan Bates' Railscasts on the subject were extremely helpful:
Episode 155: Beginning with Cucumber
Episode 159: More on Cucumber
I hope this blog post helps anyone out there trying to get set up with Cucumber and Rspec in Rails 3.
DRYer CSS with Less
One thing I have disliked for a while about web development is CSS (Cascading Style Sheets). We all love to have web apps that look pretty but when it comes to writing CSS you tend to find that you end up repeating values and this is what I dislike about it.
There are various solutions to deal with this problem such as Sass but in most cases this means taking the time to get used to a new syntax. Luckily I found this Less, Less is a way of DRYing up your CSS using Variables and Mixins without taking the extra time to learn a whole new syntax.
Less is easy to install assuming you have RubyGems installed simply type:
Nesting
Nesting with Less couldn't be simpler in your old CSS you may have something along the lines of:
Variables
Once again these help to tidy up your CSS by allowing you to declare elements such as colors etc. at the top of the file like so:
Mixins
Say for instance you use rounded corners on various elements in your layout, mixins can be extremely helpful in making sure we not only cut down on the amount of code we have to write but keeping things consistent for example:
Finally to convert your .less file to a working .css file to be used on your application simply type the following in to the command line:
I have only covered the basics of what you can do with Less hear but make sure you head over to http://lesscss.org and give it a try for yourself.
*UPDATE* For Textmate users there is a bundle you can install to make life even easier for yourselves http://github.com/appden/less.tmbundle
Jubilee now released
Hey all,
well it's finally here, what started out as an application purely for my own use, I've finally got it to a stage where I am happy to release it for general release so here she is, http://github.com/lrichmond/jubilee.
Sadly I am one of those developers who gives all their applications a working title based on a comic book character, but Jubilee is designed to be a simple blogging application in which the developer can either use it as it stands to start their own blog, or they can take it and use the application as a starting block to build something bigger.
Jubilee has a fully WYSIWYG editor courtesy of the wysihat-engine gem for writing your articles and creating the different categories within your blog, comment moderation to help avoid all those spammy comments you may encounter, and a basic configuration section where you can set things like the title of your blog, some basic meta data, as well as the default email address that will be used for your contact form and to notify you when a comment that requires moderation. All this is contained within a simple administration section.
Jubilee is far from complete but I felt it was at a stage where any Ruby on Rails developer whether a beginner or and advanced Ruby guru would be able to pick it up and use it.
Jubilee is currently in use for the blog you are reading now, and I would be interested to hear from anyone who does try it out I am always open to the thoughts and comments of others, so what are you waiting for? give it a try.
Gems used:
http://www.gemcutter.org/gems/wysihat-engine
http://www.gemcutter.org/gems/less
http://www.gemcutter.org/gems/gravatar_image_tag
Plugins used:
http://github.com/technoweenie/restful-authentication
http://github.com/technoweenie/permalink_fu
DRYing up your database config
One of the things that I love about Ruby on Rails is that it allows you to implement the DRY andREST principles with a lot of ease.
As anyone who has looked at Ruby on Rails knows the database config file (database.yml) is one place that could do with DRYing up for instance here is how a standard database.yml might look:
As you can see this isn't exactly DRY, so here is my solution to this problem:
as you can see this solution is much DRYer and in my opinion much easier to work with.



