Welcome to the Thinking in Rails site.  This is a site where fans of the Ruby on Rails world can come and start to learn how to think in the pragmatic, agile, and DRY way that the Rails world requires.

This site (or at least the URL) was born out of a conversation with another programmer about the different ways that you have to think when you are a Rails programmer.  It’s not just the pragmatic principles, but the impression that there is a single “right” way to do a given task.

As a perl programmer who moved up the ranks from the original cgi-bin style pure perl scripts, then embedded into the apache server with mod_perl, and then the pseudo-frameworks of EmbPerl and HTML::Mason.  While there are perl web frameworks (Catalyst and MayPole for example), they just didn’t seem to…. feel right, or at least give the same “good feeling” that you get from looking at an elegant Ruby on Rails application.

To quote the Agile Web Development with Ruby on Rails book:

But there’s something else to Rails—something that’s hard to describe. Somehow, it just feels right. Of course, you’ll have to take our word for that until you write some Rails applications for yourself

I’m hoping this site will help people like myself who are new to Rails and Ruby to find a few bits and pieces of help to get them going on their way to being better and more productive Ruby on Rails programmers.

The Ins and Outs of Serving Rails

One of the biggest failures I found starting in Rails was the lack of a standard for hosting.  In the mod_perl or php world, the standard apache distribution has everything needed built in to the standard distribution, and you’d be hard pressed to find a hosting system (of any size) that doesn’t have them.

Rails on the other hand, seemed to have a boatload of ways to serve itself.  There doesn’t seem to be a “standard” webserver.  You have mongrel, nginx, phusion passenger (mod_rails), lighttp… the list goes on.  And it doesn’t seem that there’s an accepted “proper” way to do the webserving yet.  Maybe it’s a case of different tools for different cases, maybe it’s just a symptom of a system that’s relatively young (compared to the apache/perl/php world).

Rails Resources

As with all noobie learners, one of the best ways to learn about Ruby and Rails is to read sites on the net.  This has it’s good sides and bad sides.  On the good side, there’s a vast amount of information out there, free for the taking.  People are willing to throw out information about coding skills, projects, give you access to their source code…. all for free.  On the bad side, it’s the wild west.  There’s scads of information, mostly unsorted, and a lot of the people sharing it are on the edge of the technology, and it’s very easy to get lost in the latest-and-greatest and completely miss learning the simple and fundamental lessons.

To quote a game programming book I read once long ago: “First make it work, then make it work fast.”  It’s fairly easy to move that to the ruby world.  “First write a rails app, then write one with the latest wiz-bang plugin.”  OK, maybe it doesn’t work that well :)

Here’s a list of some of the sites I keep in my RSS reader for keeping up to date…

The Challenge of Learning Ruby

One of the biggest challenges I have as a Perl programmer is dealing with the change in the underlying language that Rails is written in, namely, Ruby.  To help with this I’m working myself through Project Euler to do a couple of things

  • Force myself to work through problems in Ruby
  • After solving the problems, see how others did them

The last item is the most important.  I generally start off in a very perl-ish, procedural way.  When the answer arrives it’s a real eye opener to see how others solve the issues.  For example, for one problem after solving it in what I thought was a fairly elegant way (a couple of short functions), seeing the first Ruby based solution in the forums the programmer had used a quick Monkey Patch (modification of the base Integer class in this case) to simply add a function that did what he wanted.  I had never even thought of this!  I knew the capabilities of Ruby to do this, but my brain just hadn’t triggered the idea that this was a good solution.

The pros and cons of Monkey Patching are a discussion for another day of course :)

I’m fairly proud of myself, I have worked through some of the problems and even just wrote the following line of code… on purpose!

(1..100).inject { |s,i| s*i }.to_s.split(//).inject(0) { |s,n| s + n.to_i }

I admit that my perl-ish nature of doing it all on one line came out a bit :) The actual solution that I came up with was a bit nicer of course!

Bought 2 Rails Books

Got a couple of Ruby on Rails books out at the local Chapters today. After hearing a bunch of reviews, I picked up “Head First Rails”. This has a very unique way of teaching, obvious not only from the front page of the book (which immediately said to me “get rid of this and go onto the next book, this is crap”) to the inside and first chapter I’m going through. However, give it a shot and read through the introduction chapter and give it a shot. It’s different for sure, but in a good way.  One of the biggest things for me was the first chapter wasn’t a “how to install rails” section.  It really gets right down to business, which is a nice change.

Also, on a whim I grabbed “Advanced Rails Recipes”. The latter one I had seen before, but the idea of just having a book full of “how to do random thing X” was fairly appealing.  I don’t technically need this just yet, but it’ll be nice to have a paper copy for when I do reach that stage :)

Discovering Ruby With Ruby Warrior

Thanks to the FV.rb last night I discovered Ruby Warrior, a neat and fun way of learning ruby.  It goes like this….

First, head to http://github.com/ryanb/ruby-warrior/tree/master and download the tree by using “git clone“, then simply run “bin/rubywarrior” out of the main ruby-warrior directory that the git clone command creates.  The first run will create a profile and set up the initial part of the “game”.

The “game” is a bit like the old adventure text games, with a simple ASCII “dungeon” that you see your guy move through, and as the levels progress you will encounter monsters, harder monsters, captives to rescue, and so on as you move from one side of the dungeon to the stairs on the other side.  The system is turn based, so you are basically creating yourself a little state machine.  You basically check to see if there’s something in front of you and if not walk, if it’s an enemy, attack, etc.

To do this you end up doing something like this:

  1. You look at the README file in the ruby-warrior/beginner-tower/level-001/ directory.  You may have “intermediate-tower” instead of beginner depending on the level you chose during the initial setup.
  2. Follow what the README file says and edit the file ruby-warrior/beginner-tower/level-001/player.rb adding code to make your warrior move and fight.
  3. Run bin/rubywarrior and see how well your warrior moves and fights.  It will either succeed and allow you to continue to the next level (in which case go to step 1, substituting the right number in the “level-00N” directory), or you will fail, in which case, re-edit the warrior.rb file and try again.

The game isn’t for complete and total programming n00bs, but might be a bit simple for people who know programming, but not ruby 🙂  It starts out with simple commands and simple if/then/else control structures.  However, it does make it cool and interesting enough that it has kept my interest for at least until now.

Quick Thoughts – Comparing HTML::Mason to Ruby on Rails

Since HTML::Mason is about as close as I’ve come to coding Rails before now, and Class::DBI is about as close to ActiveRecord as you can get in the Perl world (well, DBIx::Class is close too), I wanted to draw some comparisons for people.

  • The params variable is %ARGS
    • As with each request in Mason having access to the %ARGS hash, each view and controller in Rails appears to have access to the params variable with whatever parameters are passed on.
  • Helpers are Components
    • All those little “helpers” or scriptlets or whatever they are called all are pre-defined components. Putting <%= form_tag %> in your page is very similar to using <& /components/form_tag &> (if you had a bunch of pre-done components of course :)
  • ActiveRecord is Class::DBI or DBIx::Class
    • Already stated above. The same Zen of Class::DBI and it’s goodness is replicated fairly nicely in ActiveRecord. There doesn’t seem to be an obvious replication of some of the really cool stuff from SQL::Abstract (using [ ] arrayrefs and { } hashrefs to create complex and/or and nested queries). The “noobie” ActiveRecord that I’ve been presented with so far has allowed for this by allowing you to do something like Thing.find(:all, :conditions => ["age > ? and age < ?", agefrom, ageto ] ). Not as cool, and I’m sure that if anyone was reading this blog they’d chime in that all you have to do is use the SuperMegaAwesomeSQL-fu plugin and I’d get that functionality. It might also be in the next chapter of the book I’m reading too.

These are the big obvious ones I’ve seen so far, will update when I find more comparisons that help me wrap my mind around this stuff.

Learn Ruby on Rails in Some Easy Steps

Are you looking for a one step further into Programming? Well, what are you waiting for when you got such amazing programming , i.e., Ruby on Rails. Well, this platform is one of the best platforms to choose if you are a beginner to programming. However, it is a community of Rubyist that helps everyone to code and learn everything easily. Unlike all other programming languages, Ruby Language is easy to use and implement.

When it comes to the rails, then this is the best and the most popular web development platform and frameworks. The benefits associated with the rails are unlimited and one day you will get inspired for real and will develop a new startup of yours on Rails. You can check the blogs and many such things of the people in the Ruby community. They help you with everything, and the response rate is too high. Here are some steps that can help you to get started with the Ruby on Rails. So let us get to it –

Master the Technologies

Mastering means that you should know everything about the code in here. There are many ways in which it can help you and should have knowledge of CSS, Java, HTML and all other development languages that are associated with the Linux. In order to master the beginner level, you have to smart enough to know where to start, and the best way is to get a hold on these languages that reused for Web Development.

Learning the Ruby Language before Rails

Learning doesn’t mean that you should be totally engaged in the theoretical books and blogs. There is no use of that if you are not implementing it anywhere. If you want to use the Ruby on Rails, then you should know about the Ruby Language first as it is all you need for a better start.

There are many courses available online and offline if you are planning for the individual study. Be fierce and make the most out of these courses and it will take you a long way up to the top. Take a leap towards the coding world with the help of Java, CSS, and HTML, and it will help you in so many ways.

Get on the Rails

Getting on the rails is all you need after a long coding class of Ruby. Don’t go out in some number of days but all you need is practice for now, and after a long practice you should move to the rails. There are many courses offered to get started with rails, and it is all you need.

Choose up online or offline courses that are so much popular in the market, but it can be a study full of doubts. So the best way is to get on the rails or join up the community of Ruby on Rails. These people will help you with so many things, and you will get detailed knowledge about it.