Errors Installing the pg Gem When Using Heroku Postgres.app

I’ve been using the PostgreSQL Mac OS X app from Mattt Thompson and Heroku for quite some time now.  If you don’t know what it is, it’s a drop in app bundle for the PostgreSQL database.  There are many ways that work, this just happens to be really simple.

I use PostgreSQL with my Ruby on Rails projects and combine that with the pg ruby gem.  

I ran into a situation where the pg gem would not install because it could not find pg_config in a known location on my Mac.  The error occurred on Rails 3.2 but 4.0 may show the same behavior.  

The Error

The error can come up when running a bundle install or just a straight gem install pg from the command line. The resulting error may look something like this:

Installing pg (0.17.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.
.
.
.
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v ‘0.17.0'` succeeds before bundling.

The Solution

I already mentioned the problem is the gem install not finding pg_config during installation.  So let’s find it.

1. First, find where pg_config is located.  Run this command from a terminal window:
which pg_config

Should display something like this:

/Applications/Postgres.app/Contents/MacOS/bin/pg_config

2. You can tell RubyGems where your pg_config file is located:

gem install pg -- --with-pg-config='PATH_TO_YOUR_PG_CONFIG'

For example, pg_config is here on my system:

/Applications/Postgres.app/Contents/MacOS/bin/pg_config

So I would install the gem this way:

gem install pg -- --with-pg-config='/Applications/Postgres.app/Contents/MacOS/bin/pg_config'

The pg gem should now install. I hope this helps.

UPDATE: Scott Watermasysk points out another good solution:

Use TinyURL from Ruby

I recently found myself needing to use TinyURL on a client project.  I did a bit of scouring the web for some Ruby code to solve the problem but with little success.  Much to my surprise they don’t have an available API, but they do have a way to access over HTTP.

This is a simple Ruby class to use TinyURL.  Note: this depends on HTTParty, so add to your project.

class Tinyurl 
include HTTParty
base_uri 'tinyurl.com'

def shorten(url)
self.class.get("/api-create.php?url=#{url}")
end
end

You can find the Gist on Github. Hopefully you find this code useful. Enjoy!

I Backed The Ruby 2.0 Walkthrough on Kickstarter and So Should You

Ruby20

It was announced at RubyConf that Ruby 2.0 would be released in February 2013 and a preview available immediately.  If you use rvm, you can try it out pretty easily.

The problem is, there are many changes coming.  How are you going to know what’s different from Ruby 1.9.x?  What about all the way back to 1.8.x?  I think it will take any one of us a significant amount of time to sort it all out, but it doesn’t have to.

There really is a rather simple answer; it’s a Kickstarter project by our Ruby friend Peter Cooper called The Ruby 2.0 Walkthrough.  Peter is looking for a small sum of money to help pay for his time to create this valuable asset.

What do you get?

Ruby 2.0 launches in February 2013 and at that time I’ll be selling the screencasts alone for $19 and the screencasts + e-book for $29. By backing the project now, you’ll get the same material for less and depending on what tier you go for you could get access to special bonuses and benefits that I WON’T be offering when it goes on general sale (like update e-mails, consultancy time or a limited PRINT edition). Also, having people pledge to the project will ensure I stick to it and get it done which is the main motivation for this campaign.

I am backing this project and so should you.  Why?  

  • The resource created will be valuable to everyone moving to Ruby 2.0.
  • The small amount of money to back the project will pay for itself in the time you save.  Minutes based on your hourly rate, I’m sure.
  • Peter would like your support.  He provides so much value to our community with his weekly newsletters for Ruby, JavaScript, HTML5 and others, that when someone so giving asks for support..it’s a no-brainer.
  • Peter needs the pressure from us, by raising the money to get it done.
Head over to Kickstarter and support The Ruby 2.0 Walkthrough.  Many less worthy projects have been funded.

 

Get Your RubyTapas On

Rubytapas

I really love the efforts being put forward by people in our developer community, lots of cool new tools and especially screen casts.  Screen casts are a great way to spend some time and learn something new.

One new screen cast that has quickly become one of my favorites is RubyTapas by Avdi Grimm.  Avdi is a speaker, writer and a Ruby Rouge.

What’s RubyTapas?

These are short, 2.5 to 7 minutes in length, but are laser focused on a very specific aspect of Ruby and published 3 times a week. 

RubyTapas is for the busy Ruby or Rails developer who is ready to reach the next level of code mastery. Short screencasts three times a week will introduce you to a wide variety of intermediate to advanced Ruby concepts and techniques, as well as core Object-Oriented design principles. Lead by head chef Avdi Grimm (author of Exceptional Ruby and Objects on Rails), you’ll go from journeyman to master, one small, tasty plate at a time.

As I write this Avdi has published his 13th episode which covers singleton objects.  The growing list of episodes can be found on the RubyTapas site.   Subscribing to the full list requires a subscription, only $9 per month..so a great deal.

What’s to love about these?

Each episode is a super focused topic, great video and great sound.  This isn’t the best part in my humble opinion; each episode comes with a very well commented Ruby file as well as an HTML document containing the episode explained so you can get a deeper understanding of the concept.  

I have gone through all the episodes and they are pure Ruby, no Rails no Sinatra..just pure Ruby.  I have been working with Ruby for a good number of years and I am learning a bunch from these, great style and techniques.  I wouldn’t say they are for beginners but your mileage may vary.

I’m not affiliated with Avdi at all, just a happy subscriber.  It’s sometimes hard to filter the good from the bad out there.  

Happy Hacking!!

Minitest Not Running My Unit Tests

I have started using minitest for Rails 3.x unit testing and since it comes with Ruby 1.9.x by default, it seems like a good direction to take my testing.

I am using the great gem by Mike Moore called minitest-rails which has a minitest dependency so I can easily have the latest version of minitest.  This gem helps to more cleanly integrate and use minitest in our Rails 3.x projects.

As part of my setup I use Autotest so my tests run automatically when files change.  I noticed none of my unit tests were running and upon further inspection, minitest was looking in test/unit and test/unit test directories but not in the test/models folder, which seems to be the minitest default.  

Opening up my .autotest configuration file and adding the following:

Autotest.add_hook :initialize do |at|
 at.add_mapping(/test\/models\/.*\.rb/) do |_, m|
  at.files_matching %r%^test/(models)/.*\.rb$%
 end
end

After restarting autotest, my unit tests are now being tested.  I hope this saves someone some time.

RailsConf 2012 Wrap Up

IMG 0370

I was fortunate enough to be able to work out attending RailsConf 2012 in Austin, TX.   This was the first time on many years that the conference was not organized by O’Reilly but rather Ruby Central, Inc.

I have to go on record and say I usually avoid cities but the city of Austin is a great place and would not hesitate to return.  The people are friendly and there is so much diversity in the city that there is something new on each corner.  I noticed an abundance of restaurants with so many different types of food.  I can’t say I had a single bad meal during my journey.  Everyone I spoke with about the trip said I had to try the BBQ, and they were right…it was fantastic.

IMG 0379

Many of the sessions overfilled the room.  This on in particular exemplifies what I’m talking about.  I bet the fire marshal wasn’t aware of these.  Overall the floors were pretty comfortable.

It was often difficult to decide which sessions to attend, with 3 full-tracks there always seemed to be two talks during the same time slot I wanted to take.  I usually decide which sessions to attend by how applicable they are to current work.

One of my favorite sessions was by Obie Fernandez about using Redis with Rails.  Although the examples of the talk were from his recent startup, they were excellent and showed integrating Redis into a Rails application not to remove ActiveRecord but to compliment it.  Obie discussed a gem he released to help the integration called redis_props along with sample code used in the talk.  The code is clean and concise…great stuff.

Another talk I found personal value in was the Semi Automatic Code Review by Richard Huang.  Richard is the creator and maintainer of the Rails Best Practices gem.  In the talk he discusses another related open source project called Railsbp.com which allows for your code to be reviewed when committing to Github.  The results will be displayed on the Railsbp.com site where you can change the code right there and commit back to your repo.  Very informative details produced from the site, GitHub allows hooks into the service and thoughtfully open sourced.  I wasn’t aware of the site before but now I am using it regularly.

The other talk which I took a lot away from was Digging Deep with ActiveSupport::Notifications by Matt Sanders.  This talk when into great detail with many examples of using notifications in your applications.  It is similar to the event publishing and subscriber model from other platforms such as .NET.  Having spent many years writing .NET applications this talk brought back many memories of this pattern.  The techniques exemplified here I had never used in Rails but do need this functionality on a new project.  

UPDATE (05/03/2012): One talk that was intended to be included here, is from Lori Olson.  Her talk titled, Mobile Rage – What causes it & how to fix it (Confreaks), takes the view of web application use on a mobile device from the user’s perspective and how developers can implement very simple techniques to ease the pain.  I recommend this one highly, good stuff and some tips I was not aware of.  I admit I have some sites that can take advantage of this.  

IMG 0387

The final keynote of day one was from a non-Ruby developer, Rich Hickey, which seemed to be out of the ordinary.  Maybe he was there to pull some Ruby developer to the Clojure world.  It appears Rich is trying to convince these two Rubyist that LivingSocial would be better with Clojure.  I wish I could have overheard the conversation.

There were three very large, two-sided, white boards used for companies to post jobs, and they were pretty full of opportunities.  I noticed there were far too many companies attempting to make the next Facebook or Twitter and not enough companies creating really useful applications.  There were exceptions from what I could see, but too few.  I remember the same thing happening around 2000 and then the bubble burst.  Apparently we are not better from this event in history because we have not learned from it.

I finally met face-to-face many friends I only knew from various social networks with lively hallway track discussions.  I think this is the #1 reason to attend conferences.  The materials from the talks are available everywhere and with Confreaks recording all the sessions, you can watch the show later.  You can’t however, experience meeting new friends and seeing old ones without attending.

I recommend every Rails developer attend just one of these events, well worth the time and effort.  The next on is in Portland, OR from April 29 to May 2, 2013.

Goruco 2011

IMG 0070

I had never had the opportunity to attend Goruco in New York City before, not because I couldn’t make it but rather because I wasn’t fast enough to get a ticket before the conference sold out.  Now I can understand why it sells out so fast, it is a fantastic conference run by a great group and organized with precision.

I decided to make the trip from CT to NYC the same day as the conference and return the evening after it ended, making for a long day indeed.  Getting up at 3:30 AM seems almost unnatural to drive an hour to meet a friend to make the trip by train from New Haven and arriving at Grand Central Station just after 7:30 AM with my friend and fellow Rubyist, Mike Morris of RecDesk (great software for your recreation department, by the way).

A short trip by subway to lower Manhattan put us at Pace University with plenty of time to settle into the conference.

The Venue

Pace University is the host for Goruco and has been in the past.  Since it is a university and setup to handle students, it makes a perfect back drop to spending the day talking about Ruby.  The setting in downtown Manhattan is a great place in a wonderful city.

IMG 0083

Just a short walk from Pace visitors are treated with the new World Trade Center under construction.

The Lineup of Talks

Whenever I attend a conference there are always talks that stand out for me, either because the content is great or the topic is something I am working on or interested in at the moment or maybe both.

IMG 0079

As you can see here, Evan Phoenix waves to the crowd while demonstrating some sleight of hand.

There were 7 talks plus RejectConf and of the seven, Jeremy Ashkenas’s talk titled Coffeescript for the Well-Rounded Rubyist and Evan Phoenix’s talk, Build it and they will come (Rubinius Edition) were the two talks that stood out.  Jeremy is the creator of CoffeeScript and Evan the creator of Rubinius and this fact alone makes their deep knowledge shine through. When a speaker knows a subject as deep as these two, it’s obvious in the delivery and the their ability to answer any question in great detail.

The announcement at RailsConf that CoffeeScript would be included by default in Rails 3.1 and the fact that I have never enjoyed writing JavaScript meant I really was looking forward to this talk.  I had been playing around with CoffeeScript recently after listening to the screencasts from RailsCasts and PeepCode and really liked what I saw.  An opportunity to hear the creator of CoffeeScript, Jeremy Ashkenas, speak could not be passed up.  

Engine Yard has been 100% committed to Ruby and the development of Rubinius for a long time and this level of commitment has piked my interest over the past several months.  I have spend time with Rubinius, testing my applications and using it for new development.  It has been very stable and performant and I look forward to the day it supports 1.9.x.  I think once we see version 2.0 will be the time to start moving Rubinius to production.  So this talk was important to me and Evan did not disappoint.  He laid out a clear roadmap for the product with a call to action for developers to use it, report bugs and help fix them.

The other 5 talks were also really good, along with the end of day lightening talks made for a day of learning.

New Friends

I met up with a lot of folks who I only knew from Twitter, blogs or some other way.  I always find it interesting to walk around and try to catch a glimpse of people’s name badges to see if they are familiar.  It’s also interesting to try to match a Twitter avatar to a real face.

I am glad for the opportunity to meet these people finally face-to-face.

Missed Opportunities

The conference organizers planned for a cruise on the Manhattan water which included dinner and drinks but our lack of planning left us to only watch as others sailed off.  After a dinner and a couple cold beers we headed back to CT.  The trip home seemed like a longer journey than our arrival, finally getting in at 2:00 AM.

I would have liked to spend the entire weekend in the city and attend all the activities the organizers planned but timing didn’t work out.  I am sure everyone had a great time.

Next Year

It was a great event covering a great day.  I plan to be back next year but I will be spending the weekend in the city and hopefully there will be another cruise at Goruco 2012.

If I had one suggestion to make to those planning Goruco next time, I wouldn’t mind seeing this as a two-day event full of talks.

InfoQ: Exceptional Ruby

Exceptional ruby

I picked up a copy of the new book by Avdi Grimm titled Exceptional Ruby, an ebook entirely focused on best practices relating to error handling in Ruby.  I have to say it’s a great book and really goes into nice detail about a subject most developers treat as an afterthought.  From the book’s web site:

Exceptional Ruby is an in-depth guide to exceptions and failure handling in Ruby. Over 100 pages of content and dozens of working examples cover everything from the mechanics of how exceptions work to how to design a robust failure management architecture for your app or library. Whether you are a Ruby novice or a seasoned veteran, Exceptional Ruby will help you write cleaner, more resilient Ruby code.

I also had a chance to talk with Avdi about the book for InfoQ, please give it a read.

Readers can also receive a $3 discount off the already great price of $15, just go check out the interview to receive the discount.

InfoQ: Learning Ruby on Rails with Michael Hartl

Rails3tutorial cover

My interview with Michael Hartl of the Ruby on Rails Tutorial series is now live on InfoQ.  Michael is such an interesting guy and has a diverse background ranging from physics instructor at CalTech to Ruby on Rails teacher.

Please give Learning Ruby on Rails with Michael Hartl a read.

You can find out more information about the printed version of Michael’s book Ruby on Rails 3 Tutorial: Learn Rails by Example (Addison-Wesley Professional Ruby Series) on Amazon.com.

InfoQ: Meet the Goliath of Ruby Application Servers

Pr ruby

I have had the opportunity recently to discuss Goliath, a new Ruby application server from PostRank Labs, with its creator Ilya Grigorik.  The article and interview titled, Meet the Goliath of Ruby Application Servers, is now up on the InfoQ web site, please give it a read.  I think it is a unique and very useful project worth giving a look.

I was fortunate enough to have a look at the project before it was released and was able to work with it.  I have to say that I am really excited about this project to solve some problems in my own work.  I had previously thought of using node.js but was turned off by the thought of having to write some server-side JavaScript.

Goliath uses Ruby 1.9+ to take advantage of fibers (continuations).  This is one example why developers should be moving to Ruby 1.9.2 and beyond.  Hopefully we see more projects like Goliath that take advantage of 1.9’s features and prod developers to a better Ruby.