Installing Ruby 1.9, Rails 2.3.5 and Getting RSpec/Cucumber working on Mac

There was a little bit of jumping around to figure this all of, so I figured I’d put it all in one place here

Installing Ruby 1.9

  • Download and Unpackage Ruby from, the cd into the dir
  • Run `autoconf`
  • Run `./configure –enable-shared –with-readline-dir=/usr/local`
  • Run `make && sudo make install`
  • Add /usr/local/bin to $PATH (most likely in ~/.profile or ~/.bash_profile)
  • Run `ruby -v` and ensure it now says version 1.9.1

Installing Gems

sudo gem install -v=2.3.5 rails sqlite3-ruby rspec-rails cucumber-rails webrat -v=1.2.3 test-unit database_cleaner

Loading RSpec and Cucumber

In your app..

script/generate rspec
script/generate cucumber

Then open features/support/env.rb and comment out line #18 to remove warning when you run cucumber
You should be all set, if not, leave me a comment – I’ll be pretty quick about responding to them.

Update Child Model From Parent’s Attributes in Rails

You probably already know that you can add child models relationships through the parent model once you have set up your models appropriately:

BlogPost < ActiveRecord::Base
  has_many :comments

Comment < ActiveRecord::Base
  belongs_to :blogpost

..and then you can do something like:

@blog = => "My First Post")
@comment = => "Great Post!")
@blog << @comment

We use the << method to make a foreign key relationship. When we save the blogpost model, it automagically saves the @comment model, and associates it with blogpost record via a foreign key, so that we can later say

puts @blog.comment.first.body
# "Great Post!"

But, what you may have not known about is Nested Attributes. This is a slick little feature, turned off by default, that allows you to create the child model via parameters of the parent model. To enable it, simply add this method call to the parent model:

BlogPost < ActiveRecord::Base
  has_many :comments

  accepts_nested_attributes_for :comments

Now, you can create the same blog/comment models & relationship with a quicker syntax:

@blog = => "My First Post", :comments_attributes => [{ :body => "Great Post!" }])

Upon saving, this will create the BlogPost, create the Comment, and set up the foreign key relationship. Sick!

To learn more, check out:

Display navigation in footer in Drupal

Here is a quick code snippet to put that pretty, pipe-seperated navigation into the bottom of your site, so that Google can eat it all up.

foreach(menu_navigation_links("primary-links", 1) as $m):
  $arrNav[] = l($m['title'], $m['href']);
echo implode(" | ", $arrNav);

Substitue “primary-links” for the internal menu name of your choice. Enjoy!

Add CSS File To Specific Pages In Drupal

I get asked a lot how to go about adding certain CSS files to only certain pages of a Drupal project, rather than every page. This is commonly desired when you are using a drastically different front page in comparison to your drill pages. To achieve this you will want to use the drupal_add_css() function provided by the Drupal API.

It’s very basic in functionality:

drupal_add_css(path_to_theme() . '/layout-fixed.css', 'theme', 'all');

Given a path to a CSS file, it will load it where ever the function is called. The second param specifies whether you are theming a “theme” or a “module” with it, and the third param reffers to the “media” attribute of the <link> tag.

I’ve seen many coders drop this call right into the page or node template they are theming. That is really less than desired, as it tightly links a css file to template file. Say you wanted to use this css file 5 times, you would have to add it to 5 files. That duplication would make it time-consuming to change if you had to alter the name of the file, for example (and that is provided you can remember where you put every call to drupal_add_css()).

A cleaner approach is to put it’s call in your template.php and use some logic to control when to use it. Something like:

if($_GET['q]=="node/2") {
drupal_add_css(path_to_theme() . '/crazy-style.css', 'theme', 'all');

Doing this will ensure that all of your dynamically added CSS’s files live in one spot, making it super easy to add or extend to.

To remove an existing CSS file per page, try something like:

 $arrCSS = drupal_add_css();
  $vars['styles'] = drupal_get_css($css);
  return $vars;

Take charge of your web app’s billing with Chargify

The web is literally bursting with great ideas and it seems that every day, new web applications are emerging that are offering really awesome functionality to make life easier and fun. Us developers spend large amounts of time coding up these apps, and one of the trickiest parts is always the merchant transactions. Chargify has taken care of all that by offering you access to the most popular merchant gateways, with no transaction fees, only a monthly fees based on volume. Simply sign up for an account based on your volume, create your products and pricing tiers, and hook into their API via your web application – it takes care of the rest! No need to store credit card information, write recurring billing software, etc. Check it out

Remove Your Folder From SVN

Did you ever have a folder that was nested with .svn folders and you wanted to quickly remove them and just make them a non-versioned folder? Perhaps because you are going through old repo checkouts that are too out of date to care, or you want to copy a repo-ed folder to a new project without it being externalled, or maybe because the folder got screwed up on a commit and you just want to recommit it? Try running this unsvn code.

find . -name ".svn" -exec rm -rf {} \;

Just save this code to a file (I call mine “unsvn”), run it from the parent level directory and it will remove all .svn folders in itself and all of it’s children.

What would you like to see in project management software?

As web developers, whether you are a designer or a programmer, you have to manage tons of information to complete your project as quickly as possible, and with all of the requirements of the client in mind. It doesn’t matter if you are a large web shop, or the freelancer starting out with a small number or projects, you need to be organized. Organization of data, feedback, tasks, contact information, assets, and any other requirements ensures that you can maintain the big picture of the project, all bullet points, and that you have a paper trail of where direction and decisions came from.

However, it seems that though every size shop requires the same things, we can’t all seem to settle on the same software to organize our projects. The one-man show doesn’t want to pay $24 a month for a tool that deprives him of time-tracking and is deeply ingrained in multi-user collaborative features. The large company has problems with its oversights: it doesn’t account for maintenance or non-project work items, it doesn’t organize e-mail tickets, it doesn’t incorporate invoicing, and other random nuances that large shops have. Therefore, large shops are forced to have a number of subscriptions to varying SaaS apps, with redundant data, making an uneasy experience for the workers. This is no slight of BaseCamp, the extremely popular software is just one of many who offer powerful tools for managing projects.

I have a vision for software that manages the way your web shop works, and not just how you organize projects. My ultimate goal would be to develop a turn-key application that allows companies large a small to handle the life cycle of a client and their project. We are at an amazing time in web development, where information accessibility and frameworks are turning hobbyist into professionals. Larger shops are at a huge advantage too, with an infrastructure in place, and the business world acknowledging having a web presence like never before, your revenue is only limited by your turnaround times.

That’s why I am calling on you, the reader from all walks of life, to tell me about your day-to-day work process as a web developer, and how you vision an organizational application to handle what you do. Please leave a comment below, and I promise not only to keep the development of this application customer-driven, but to also to give you beta invites (so make sure to include your email address!)

Thanks in advance!

Current Items

  • Client Management
  • Project Management
  • Web Development Specific Roles: Project Manager, Developer, Freelancer
  • Invoicing
  • E-mail Maintenance Ticket Integration
  • Create Billable Services – such as Email, Hosting, SEO, Consulting, etc
  • Wiki / KnowledgeBase ( thanks Mikey Van )
  • API for accessing/submitting information