The Archives

SEARCH

I’m Attending

CodeMash

Tag Archives: ruby

Issue Installing Gems with Ubuntu 10.04, RVM and zlib

Posted in: Programming by Steve on October 30, 2010

So after writing up the tutorial on getting a Linux VM setup, I came across and issue where I couldn’t install gems. I would get the following error message after trying to install any gem:

ERROR: Loading command: install (LoadError)
  no such file to load – zlib
ERROR: While executing gem … (Name Error)
  uninitialized constant Gem::Commands::InstallCommand

image

I found the answer in the RVM documentation: http://rvm.beginrescueend.com/packages/zlib/

Execute these commands:

rvm package install zlib
rvm remove 1.9.2
rvm install 1.9.2 -C --with-zlib-dir=$HOME/.rvm/usr

This will install zlib in your ~/.rvm/usr directory.

I could then move forward setting up my development environment.

My First Real Rails App

Posted in: Programming by Steve on October 27, 2010

codemasher As CodeMash approaches, I wanted to build something that would get me more formally introduced to rails 3.  I also wanted to set it up so others could see it and view how I was coding it so I could get some direction.

So I present to you, the Codemasher. It’s a quick and dirty website that returns a random session to attend.  It uses the REST API provided from the CodeMash website and is the simplest site I could come up with.  I have deployed an example up on Heroku at http://codemasher.heroku.com

I hope to have it working where it remembers the sessions that you didn’t like. Another thing is to set it up to look at the sessions that will happen in the next chunk of time slot(s) so you could look at it at the end of a session and try to find another session to go to.

It was inspired by WTFSIMFD (http://whatthefuckshouldimakefordinner.com) but without the curse words.

All of the code is available on github at http://github.com/underwhelmed/codemasher.  Please take a look and see how you like it, and if you would make improvements to it, I’m all ears.

Setting up a Linux Rails Development Virtual Machine

Posted in: Programming by Steve on October 26, 2010

I wanted to do some Rails development on my Windows machine, but I didn’t want to worry about compatibility.  So here are my steps to build up my development environment.

First thing is to download an Ubuntu VMWare Appliance.  I got my machine from http://vmplanet.net/node/114

Second was to rename the machine – I used the tutorial here http://www.liberiangeek.net/2010/06/how-to-quickly-change-computer-name-in-ubuntu-10-04-lucid-lynx/. Since my server/network naming is based on characters from Futurama, I selected Leela as my rails development VM.

Next was to install git – http://book.git-scm.com/2_installing_git.html, curl and the developer tools

sudo apt-get install git-core
sudo apt-get install curl
sudo apt-get install build-essential

Next, time to install the base ruby libraries:

sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev

The next step is to install ruby gems and make sure that you have the latest version:

sudo apt-get install rubygems1.8
sudo gem update –system 

Now, you’re ready to start getting your environment setup for rails.  By default, new rails applications use SQLite3 so we’ll install it and get it ready for use in our applications if we so please.

sudo apt-get install libsqlite3-dev sqlite3 sqlite3-doc

Our next step is to install Ruby Version Manager. This package allows you to set specific versions of ruby (1.8.7 or 1.9.2 are the main versions) and set specific gemsets:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Then open up your .bashrc file (located in the home directory, ~), and append the following code to the end of the file:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

Now you can close your terminal session, open a new one, and RVM will be ready for you to use. 

There are a few editors that you can use (gEdit, Aptana Studio 3 or even JetBrains RubyMine which is a paid for application). I prefer TextMate on OS X so I use gEdit along with a few plugins to get it to look like TextMate.

That should get you started on your way to get developing on a linux VM, or even a regular PC set up with linux on it.

References:

How to Generate Views for Devise in HAML

Posted in: Programming by Steve on October 20, 2010

UPDATE (5/16/2011) – As Declan points out, this is no longer the case.  you can use the master of devise from github to get this functionality back.

http://fredwu.me/post/445463159/rails-use-haml-templates-with-devise

—————————

I have been moving one of my sites to a rails application, and I am using the HAML view engine to make all my templates.  I am also using Devise as my authentication gem.  I am going to be doing some customizations of the views, however, by default, devise generates the views in ERB.

This is how to get the devise generator to use a HAML template instead of ERB.

Add the following to your GEMFILE:

gem 'haml'
group :development do
  gem 'hpricot'
  gem 'ruby_parser'
end

Then execute the following statements in a terminal/command window:

bundle install
rails generate devise:views -e haml

This will create the views for devise in HAML.

Learning Ruby for the Web Presentation

Posted in: General by Steve on October 18, 2010

Ryan Briones presented “Learning Ruby for the Web” at Refresh Chicago on July 28, 2010.

Learning Ruby for the Web on Vimeo

Ruby Koans – Learn Some Ruby

Posted in: Programming by Steve on October 1, 2010

If you’re not sure about learning a new language, the Edge Case guys have given you an easy way to start.  The Ruby Koans give you a way to learn the syntax of a new language in a new way. 

To run the koans, you have to have Ruby installed.  Once installed, you can download the koans and fire them up immediately.  Open a command window/terminal and type “rake”

image

That’s it! No configuration, no nothing! 

The idea behind the koans are to make the tests pass one at at time.  To do that, you have to look at where it is telling you how to “meditate” on code. 

In the first group, it is looking for the code in “test_assert_truth.rb” file. When you open it, it looks like this:

#!/usr/bin/env ruby
# -*- ruby -*-

require File.expand_path(File.dirname(__FILE__) + '/edgecase')

class AboutAsserts < EdgeCase::Koan

  # We shall contemplate truth by testing reality, via asserts.
  def test_assert_truth
    assert false                # This should be true
  end

  # Enlightenment may be more easily achieved with appropriate
  # messages.
  def test_assert_with_message
    assert false, "This should be true -- Please fix this"
  end

  # To understand reality, we must compare our expectations against
  # reality.
  def test_assert_equality
    expected_value = __
    actual_value = 1 + 1

    assert expected_value == actual_value
  end

  # Some ways of asserting equality are better than others.
  def test_a_better_way_of_asserting_equality
    expected_value = __
    actual_value = 1 + 1

    assert_equal expected_value, actual_value
  end

  # Sometimes we will ask you to fill in the values
  def test_fill_in_values
    assert_equal __, 1 + 1
  end
end

The code we have to look at is starts with the method on line 9. As you go along, there will be fewer and fewer hints because the solution has already been shown how to solve.

This was a great way for me to learn the nuances of the Ruby language.