Thinking in Rails – Part 0

Part 1

This is ‘part 0’ as it is an explanation of the tutorial, no Rails code is covered in this part – I still need to write the code. This post explains what you can expect to see in future parts of this tutorial. If there is a topic you would like me to cover then please feel free to make a request…

What is the purpose of this tutorial?

Ruby is not just another OOP language. It has many idioms and constructs which seem foreign at first. Once a developer becomes familiar with these aspects the developer tends to program in a new way – the once foreign code starts to feel very natural.

Moving from Java or .Net to Ruby (and Ruby on Rails) is a challenge, but it is worth the effort. Once you start thinking in the Ruby and Rails way code starts falling into place. To cross the conceptual chasm you need to read many articles, books and as much code as you can. This tutorial aims to assist you as you crossover. Use it as a stepping stone on your path to the land of the ducks.

How did this tutorial come to be?

This tutorial is a spin-off from the ‘Routing in Rails’ tutorial. The ‘text editor’ application covered here was originally intended to be the practical section of part 6. I started developing the application and soon realised that the actual routing work was very small, and was being lost amongst the rest of the code. I felt that the application still covered many useful topics, therefore I decided to move it into its own tutorial – and here it is.

What does this tutorial cover?

This tutorial attempts to answer two questions posted to me in previous comments and emails. One question was with regards to one to many relationships and nested resources. This was covered in part 6 of the ‘Routing Tutorial’ – here we use them to build the ‘text application’ below.

The second question was from Tom made here: “When you get to RESTful routing I would like to see an example of how to add a Save As function. This would allow the user to derive a new record in a table from an existing record. So it would start as an edit function but end as a create action instead of an update action”

The second question poses an interesting REST problem. Some readers may not agree with the solution I am suggesting here. If you have any objections to this solution, please voice your objection in a comment, this will help all of us.

In addition to answering these questions, this tutorial will cover some common Rails problems e.g. using 2 models with 1 form, has many function, YAML, testing in Rails, replacing link_to with button_to etc.

As you can see, this tutorial covers many topics. I do not intend to cover each topic in detail – I would like to, I just don’t have the time. The ‘Rails Routing Tutorial’ focused on one specific topic. This tutorial shows you a bigger picture; the aim is to help you to start thinking in Rails.

What is not covered in this tutorial?

We will not be creating the definitive Rails application. The application being developed here should be thought of as the output of iteration one. While following along you should find yourself thinking: ‘would it not be better to do this?’, ‘if we did this, the test would be much cleaner’, ‘I wonder if we can add this information to the view’. If you start thinking like that, then you are starting to think in the Rails way.

Even though it is a good idea to add CSS to your Rails application from a very early stage, I do not intend to cover CSS. I would rather focus on other topics, at least for the first few parts of this tutorial – I may include it at a later stage.

This tutorial will cover the default Rails testing and not RSpec. RSpec is good and I recommend that you look into it. The only reason I am not using it here is because it requires plug-ins. These plug-ins are version dependant and I would rather avoid the potential versioning conflicts that may result from this. The testing lessons learned here can be carried over to RSpec.

What about the Music Store?

In this tutorial we will not be using the amazing Music Store application from the Routing tutorial. Instead we can create a new application. This new application will be a plain text editor. The text editor will have a version history. This will allow a user to ‘roll back’ to a previous version of the document.

This will be a basic text editor. The intension is not to create a fully fledged text editor. The aim is to familiarise ourselves with the Rails development process so that we begin to think in Rails.

What is next?

Next we look at the basic set of requirements of the text editor application. Please let me know if you would like to know more about a specific Rails topic, I will try to work it into the tutorial.

One Response to “Thinking in Rails – Part 0”

  1. Thinking in Rails – Part 1 « Project Entropy Says:

    [...] Thinking in Rails – Part 1 Part 0 [...]

Leave a Reply