rails

Rails Plugin for VIM

I found a plugin for VIM that was designed just for Rails coding by Tim Pope. I thought the first line of the documentation was great

“TextMate may be the latest craze for developing Ruby on Rails applications,
but Vim is forever.”

It provides:

  • quick navigation commands from model to view and controller
  • rake integration
  • extends ‘gf’ command to understand Rails
  • CTRL+X, CTRL+U autocompletion
  • interface to the script commands
  • convenient log file viewing

This YouTube video shows how it works.

ruby
rails

Comments (1)

Permalink

Ruby On Rails Blog Written by .NET Developers

I found a very interesting blog called “Softies On Rails” that is written by two developers who have spent a lot of time developing software using Microsoft .NET.

Here are a few of my favorite posts on their blog:

Rails IDE for Windows after reading this post I downloaded the IDE and it’s like a mini version of Visual Studio just for Ruby On Rails — pretty cool.

Ruby 101: It’s a script

.NET to Rails Survival Guide

Why Rails? Part 3: Ruby

Why Rails? Part 5: Because I can test it

Overall a very interesting blog. Subscribed! And good luck with your new venture guys!

blog
.net
ruby
rails

Comments (0)

Permalink

Ruby On Rails - Part Four - Rake

I have always been interested in automating common development tasks. I have used Ant, Maven, and Nant pretty extensively and now I’m learning the details of Rake. There’s something special about seeing messages fly by in a command shell, and know that the computer is doing all these repetitive tasks — not you!

What is different about Rake then any of the others build tools mentioned is that you create a Rakefile by writing Ruby code, instead of using xml. There is a

I would recommend you read this excellent article on defmacro.org (take your time and read through it — it’s really worth it) that does a good job of explaining the benefits of Lisp. A cool thing, since we’re talking about build automation, is one section, titled “Ant Reloaded”, talks about how Java could have been used instead of XML. In our case it’s Ruby being used in a Rakefile.

This tutorial is written by the developer of Rake, and is a good tour through the main features of Rake. I would suggest you read it first, followed by this article by Martin Fowler which reviews some examples of interesting things you can do with a Rakefile.

I created a simple example Rakefile. I’m sure no one would actually need a script like this, but the simple scenario was good for an example of how to use Rake.

I’ve included the code below, the formatting is off because I pasted it in my blog editor, but I hope it will be a good example to someone just getting started with Rake. If you have any suggestions on how to improve this simple Rakefile example, please add a comment to this post.

# ———————————————————-

# This is just an example to illustrate how to use Rake

# By Rob Herbst

# ———————————————————-

# Require rake/clean to get the built in clean task

require ‘rake/clean’

# Require ftools to get File.copy

require ‘ftools’

# Define constants we’ll use later

HTML_SRC_DIR = “html”

WEB_DEST_DIR = “website”

IMAGES_DIR = “images”

SITE_MAP = “sitemap.html”

HTML_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.html”]

IMAGE_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.jpg”]

# Add the WEB_DEST_DIR to the list to get cleaned

CLEAN.include(WEB_DEST_DIR)

# The default task depends upon the package task

task :default => [:package]

# The package task depends upon clean, create structure, and the task to create the site map file.

task :package => [:clean, :create_structure, :sitemap] do

     puts “The package task was called.”

             # Copy over the html files

     HTML_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}”)

     end

             # Copy over the image files

             IMAGE_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}/images”)

     end

end

# Utility task to create the structure of the website

task :create_structure do

     puts “The create_structure task was called.”

     Dir.mkdir(WEB_DEST_DIR)

     Dir.chdir(WEB_DEST_DIR)

     Dir.mkdir(IMAGES_DIR)

     Dir.chdir(“..”)

end

# Task to create the sitemap.html file

task: :sitemap do

     open(“#{WEB_DEST_DIR}/#{SITE_MAP}”, “w”) do |outs|

          outs.puts “<html><head>Site Map</head><body><ul>”

          HTML_SRC_FILES.each do |f|

               file_name = f.sub(HTML_SRC_DIR + “/”, “”)

               outs.puts “<li><a href=\”#{file_name}\”>#{file_name}</></li>”

          end

          outs.puts “</ul></body>”

     end

end

ruby
rails

Comments (0)

Permalink

Ruby On Rails - Part Three - The Ruby Language

I like to dig in and learn the details of any programming language that I’m working with.

Here are some of my thoughts from my first read through of some of the Programming Ruby book. You can read the first edition of Programming Ruby The Pragmatic Programmers Guide online at RubyCentral.com..

Things I like about Ruby:

  • No explicit self. I really liked the Python language, but there were two things that got to me, the explicit self, and the __.
  • Overall, syntax seems very clean.
  • Builtin string expression interpolation using the #{name} syntax.
  • Good regular expression support.
  • Code blocks, closures and the yield statement.
  • printf
  • mixin support through modules
  • here document support
  • operators as methods you can override
  • parallel assignment
  • good class library
  • built in threading support (Ruby threads)
  • simple interop with C code

Things I’m not so sure of yet:

  • Coming from the statically typed world of C++/C#, a dynamically typed language takes a bit of getting used to. I am familiar with the concepts from using Python, but it’s something that I’m still not completely used to.
  • There are probably a whole lot of semicolons that I’m going to be deleting from the end of each line of my code. :-)
  • $, @, @@ used to indicate the type of variable. The development teams I’ve worked on have standardized on a variable naming convention, for example a leading underscore to denote member variables. In Ruby, it looks like this decision was made once for the language, which is good — I’ll just have to get used to the symbols used.
  • rescue instead of catch & ensure instead of finally is going to take some getting used to, with catch and throw meaning something a little different.

It’s a pretty short list of things I’m not sure of, and most of them are just observations on how things are different that what I’m used to. I’m looking forward to working more with Ruby, and I’ll come back to this list at the end of this blog post series.

ruby
rails

Comments (0)

Permalink

Ruby On Rails - Part Two - Setup & Configuration

I started reading the Pragmatic Programmers - Agile Web Development with Rails. I haven’t read very far into the book yet, but so far it’s as good as I hoped it would be.

I’ve also moved my blog to a new host. They have support for Ruby On Rails built right into the hosting package!

I downloaded and installed RadRails which is a very cool Ruby On Rails IDE built on the Eclipse framework. I’m actually pretty comfortable at either the command line or in an IDE. So you’ll probably see me switching back and forth throughout this blog post series.

I ran the following command on my web host:

rails railsblogjourney

which instructed rails to create a basic application for me. Pretty cool.

After that I wanted to continue validating my workflow and ensure that Rails was functioning correctly on my web host, so I generated a new controller:

ruby script/generate controller HelloWorld

and then added an index method

def index
render :text => "Hello World."
end

If you browse to http://www.robherbst.com/railsblogjourney/HelloWorld
you too can experience the awe inspiring demo. Uh…. right.

Basically today’s goal was to setup a functioning environment for the demo application and to make sure we are able to execute, some extremely basic code.

So far so good.

ruby
rails

Comments (0)

Permalink

My Journey to Ruby On Rails - Part One

I’m going to begin a series of posts on my journey to learn Ruby On Rails. My professional experience has been primarily as a C++, Java, and C# programmer. I’m totally new to Ruby the language, and the Rails framework.
I have read and created the sample application described in the following tutorials by Curt Hibbs on Oreilly’s OnLamp site:

Very nice job with these tutorials Curt, I think they are a great introduction to Ruby on Rails!
I really enjoyed the book The Pragmatic Programmer: From Journeyman to Master by the Pragmatic Programmers, so I went ahead and ordered the following

I’ve found that I don’t really learn a programming language or new framework until I try and apply it to a real world problem. So, what I’ll be doing is creating a simple public web application that will be modified in sync with my blog posts.

What I was thinking of creating would ultimately be an AJAX style web application that would allow users to enter in url’s to Ruby or Rails tutorials, tag and rate them.
The web application probably won’t be useful for anything else except as a complement to this blog post series, but I think it would be very useful for someone else with a similar background to me to be able to read through my posts, and follow along and see the web application develop.
A good friend of mine, Pete, had a cool idea; he suggested that along with the public web application, I should publish a page with the results of the rake stats output, so the total lines of code in the application are available at a published url.
What I’m looking for help with right now is any Ruby or Rails tips or links to good tutorials that people would be able to share by commenting on this post. What I think would be cool as the application develops would be to review any comments posted for suggestions as to better ways to approach what I’m doing in the application or what new features we could add to the application to show off Ruby On Rails.

ruby
rails

Comments (0)

Permalink