Chronicling my experiences with ruby on rails, web application development/management.

Monday, August 31, 2009

Blog Activity - switching blogs

My use of this blog is slowing down. i will emerge at my new blog. In this new blog you'll get all the same rails talk, just without the google/blogger chessiness.

Pre App launch jitters...

I'm going into alpha/beta testing phase of my app. I'm pretty excited but also am kinda nervous.

Whenever you launch a product of any kind, it's human nature to second guess yourself and to ask "why am i doing this?" or "Will this work?". Or the big one, am i ready

Well you are never ready, it'll never be good enough, and you missed something. Big. Shit happens. Be a man and move on.

When you mess up your git pull

Remember this chunk of code:
sudo git reset --hard HEAD

Use that code snippet when you don't care about the changes on the local machine you are git pulling and your git pull request won't merge.

Friday, July 10, 2009

superclass mismatch for class ModelExampleGroup - Solved

If you have been pulling your dick hair out, like i was, i thought i'd post this here, while i'm still in a rage.


When you are running cucumber features, you get the following shit:
cucumber features
superclass mismatch for class ModelExampleGroup (TypeError)...

At first, i commented out the remarkable line in environment.rb. I have no idea what this gem does, And i don't want to know. Hell, I only put it there because of a railscast i think, but this gem is fucking me up, so, again, i commented it out of the environment.rb file and everyone is happy. Good riddance.


I just installed remarkable-rails instead. i guess the README in the github repo says how to do it. I've not gotten the error since.

Wednesday, July 1, 2009

30 days of Rails - Handling Flash Messages

So, here i am trying to expand my closed world beyond Restful_authentication and well, basically any other technoweenie based plugin. I try my hand at Clearance

Clearance is a thoughtbot based gem which authenticates users in your web app. Out of the box, it only allows for email addresses as the login ID, which is fine for my stupid app i'm making.

However, in all my years of scaffolding, i guess i've only really used flash[:notice] for displaying my flash messages on an overall layout level. Clearance has flash[:success] and flash[:error].

The reason i found this out is because my clearance_features weren't working and i was getting 8 failures, due to the fact that I was only displaying flash[:notice]. A win for BDD i tell ya.

Gee mister, how'd you fix it

Like all expert coders, i went to the one place I can trust. Twitter. I sent out a tweet which read: twitter ruby fun: lame, hack or on track? < % = flash[:notice] ||flash[:success] || flash[:failure] % >

Most people hated this code, which is fine, as that is what i wanted to hear. While it will work, if i had a need for two flash messages at once, or if i needed to expand my flash message symbols, i'd be fucked. Enter @heycarsten

This dude turned me onto a pretty sweet gist he wrote up for me. A thousand thank you sir's to him.

Gist... Break it down hammer style.

Well everytime you see me, the hammer is on dootie...ok, hammer time is over.

  1. Create a helper called flash_helper.rb and paste this gist into it.
  2. inside the layouts directory, create a folder called partials and a partial inside of your layouts folder called /layouts/partials/flash_message.html.erb.
  3. Paste this into it(stupid stupid blogger's formatting sucks ass... so you'll have to take the spaces out)
    < p id=< % = "flash_#{type}" % > >
    < % = flash[type.to_sym] % >
    < /p >

  4. In your application_controller.html.erb you'll need to add this code to display your new fancy flash messages:
    < % = flash_messages % >

  5. In your css file, now you can create styles with the id flash_whatever. I used #flash_error{background-color: red;}, etc...If you are new to css, learn up on it son.

Yeah for heycarsten and many thanks to him for allowing me to post this code.P.s., i apologize for this shitty code formatting. blogspot sucks ass.

Monday, June 29, 2009

30 days of Rails - Hpricot parsing

Scenario - You need some information off of a website, but there are around 100 rows. This information will also need to populate the name column of your model, so you need to clean up the data. Bascially you need to parse information from a paragraph or one big string. This is where hpricot and some ruby come in handy.

html string parser - Rake task

Here is the code i ended up using, and will try and explain it at the end

namespace :sponsor do
desc "seed data"
task :seed => :environment do
require "open-uri"
require "hpricot"
doc = open("") { |f| Hpricot(f) }
@snag = (doc/"#cnnContentArea").inner_html
@snag.gsub(/<.*>/,'').split(/\n\t+/).map {|t| t.strip }.reject {|t|t=='' }.each { |t| Sponsor.create!(:name => t) }

Code explained

I needed to pull information from that actual url. All of this information lived within the div tag id cnnContentArea. inside the source of the html page, it was prepopulated with \n\t\t\t and the number of tabs varied.

Using hpricot, we open the url page and save it as an hpricot object (see the doc = line above.

Next, we take the saved page and pull out the content from the cnnContentArea div tag, and we save it as an instance variable @snag.

The last chunk of code, does the following:

  1. The @snag string basically replaces itself without any of the paragraph tags (that what gsub does).
  2. Next, the string is split into mini strings based on a delimiter, and in this case anything that matches \n followed by any number of tabs (\t). I was lucky to be able to do it this way.
  3. We then iterate through each mini string(that's what map is doing) and we then strip all whitespace, before and after the words in the mini string. (see the block t.strip
  4. As an added measure, if the mini array is empty, then it is rejected (courtesy of map)
  5. Lastly, we then take the clean mini string and add it to our model, which in this case is a simple Sponsor model under the name column in the DB.

I have to thank emitilin from IRC as he spruced up my code, but i do take solace in the fact that i knew where to go and now i have an even greater understanding of ruby and rails. I'm sure in the comments you can point me to a method that does this in one fail swoop, but when you are learning ruby, you are a winner when you get to apply the knowledge to a problem you need fixed.

Friday, June 26, 2009

30 days of Rails - Model Associations

You've picked the perfect model names for you new app, but you are unsure when to use a has many :through association or should it be a has and belongs to many association? Or should it be a simple many to many association. Wait, what about has_one and what the hell is a polymorphic anyways?

Well at this point in the game, you may understand what each of the Model Associations do, when you branch out from the basics, or don't use them for awhile, you end up forgetting when and where to use them.

In an effort to streamline the decision of when to use the various Model Associations available in your rails app, I've come up with a decision tree app called Model Association Decider. This decision tree will help you decide when to use a model association in rails. So use this app to determine which association you should use. Model Association Decider

Wednesday, June 24, 2009

30 days of Rails Series - Introduction

Well here i am. I've taken a good look at what i need out of my life, computeristically speaking, and have decided that I am going to sink even more effort into learning Ruby on Rails, the one true and just framework, praise be unto him.

Thirty Days of Rails.. WTF?

What I've decided to do is document, a post a day for a month, about what i've learned in my rails journey from today moving forward.

I will focus on rails methodologies, techniques, optimization strategies, and anything else that i end up learning.

What the 30 days of Rails isn't...

This isn't a beginners class. I won't explain myself as indepth as I would, had I started from scratch. I'm starting with a loose grasp of rails knowledge obtained from a year and a half of using the framework. That means, i know how to do shit, but i want to learn MORE so that i can create apps trouble-free from here on out. Since I've made it my journey, I will pass these tidbits on to you, the gentle reader.

So let's see where this thing ends up. I take it that I'll probably end up with a lot of posts regarding TDD/BDD testing as i know sweet fuck all about it,however, I will post what i do find out, hoping it helps someone down the road.

Populating Select menus in Cucumber

From the easy when you finally know what you are doing, column....

How the hell do you setup a select menu in a feature?

Well, it turns out it's easy. Not obvious to me, as nothing is in this testing BDD world, however. Basically For every select menu you want to use in a feature, you must create a Background scenario to populate that select menu before every feature is ran

Here's the code

Feature: Manage Driver lineup as an admin
In order to manage all drivers
As an admin
I want to be able to create and edit a list of drivers.

Given I create a series "Nascar"

Scenario: Login as admin
Given I am logged in as an admin
When I go to the admin homepage
And I follow "New Driver"
When I fill in "Name" with "Darryl Waltrip"
And I select "Nascar" from "Series"
And I press "Create"
Then I should see "New Driver saved succesfully"

Nascar and all other known shit in the code above is copyright of their respective entities. I am just using it as an example, so chilax

Now in the background step you can just create the list of series(as i have it) using factories as so...

Given /^I create a series "([^\"]*)"$/ do |arg1|
Factory(:league, :name => arg1)

Enjoy. yes it was easy, just no one told me how to do it, so i thought i'd see if i could help another soul out.

Monday, June 22, 2009

Important Cucumber step that must not be missed!

Ok, this may just be an aha moment for myself, but i always thought that when i looked at ryan's screencasts on Cucumber we're overly weird. That's right, i said it.

Now, why were they weird? Well, he started out his steps by including the following kind of Given statements:
Given I have zero articles
# or
Given I have an article named "Cheese"

Without this step at this time, there is no way to follow a article_path("blah") link at all. In my simple mind's eye, i thought there would be.

Lessoned Learned?

Stop being a moron and setup your Given statement to either start with a record or two for the model you are trying to BDD against, or make sure NONE exist, to start with a clean slate.

Saturday, June 20, 2009

Rails vs Pylons - initial thoughts

I know, I know! Comparing two frameworks is bound to be riddled with generalizations that don't help anyone and obvious features that are only "ah ha" moments to the writer of the post. However, I'm going to give you an account of my initial thoughts of Pylons, as compared to ruby on rails, a framework that I've been using for a year and a half.

Comparing Pylons to Ruby on Rails

Initial thoughts are how very similar these two frameworks are. Pylons basically admits that it takes well founded queues from rails. But who wouldn't?

If you were to design a framework today, and you think it through, any MVC framework will smell like rails, which has hundreds of contributors, all tweeking the code base. When a populist approach takes hold, you end up with some "trueisms"

All Pylons has done, from my inspection so for, is taken those trueisms as a starting point for their framework, and now are building off that on their own direction.

Common Features between Pylons and Rails

Here is what I noticed, 24 hours into trying Pylons, as it compares to Rails:

  • File structure is similar - Rails and Pylons both create a whole bunch of files to the project folder. Pylons however has more files outside of the project's directory that are used to setup information about the egg file. Think of an egg as a ruby gem, i guess.

    Again, notice that inside the QuickWiki root folder, you have a QuickWiki folder where all your code goes into. This to me, looks like what we'd see in rails. Also, notice the models, Views(Templates) and Controller is mingling with the public folders, etc...

  • Routes - these seem similar, down to the map.connect. however, i've yet to find out if they implement Restful routing. They do seperate their controller commands by controller and RestfulController, so time will tell. Again, it's just been 24 hours. On first impression, Pylons routing actually can do a lot more, then what i've seen in rails. If this feature exists in rails, i've not seen or read about it in a year and a half. In Pylons, the first routes are the ones handled last, where as in rails, the bottom of the routes file gets executed last. Here is the example from their tutorial:

    Notice again, that last line before the return. If you entered a url "/whatever" and it doesn't exist, the last route will create the page for you, based on it being the title. That title variable is passed to the show page and saved in the DB. Perfect for wiki applications. I don't think I've seen that in rails, to date.

  • Environments - Both Pylons and Rails have development, test and production environments. In pylons it appears that the environment files are housed in the outer file system, see image above to get what i'm saying. the inner file system appears to be where you'd put most of your code for the MVC part of things. Now in part two of this post, i'm sure to have written about production deployment and the differences there. if not, screw you Lulz.

  • Error Pages/ Debugging - Both have a cool stack error printout on your browser, when you fuck up. However, Pylons is interactive and you click on these arrows to get to the right code from within your browser. You can also send Pylons an email right from the error page, if you wanted.

Differences between Rails and Pylons - initial thoughts

I know i added some variances above too, but here is a list of things that is really different between the two frameworks:

  • You are making an Egg file, not a web app. - Ok, this is my spin on the whole thing, but technically you are making a python egg that will just happen to be served through the web. In rails, we are creating a web application in ruby. Not a ruby gem, not a ruby script, a full on independent web application whose sole purpose is to be viewed through an internet browser.
    While i may be putting it too simply, it was something to get used to that when you are coding you are technically creating a python egg file that you can either, give to your friends to play around on their computer, or serve it through the web, or what have you. Maybe this has to do with the fact that you are creating a WSGI application. Read Pylons concepts here for more details.

  • Pylons needs to be running in a Python virtual environment, in order to work. What that means is you can't just call Pylons create -t MyProject willy nilly. No big deal, just something to get used to.

  • Pylons uses something similar to ActiveRecord, but in the python world it's called SQLAlchemy. From the pylons site: SQLAlchemy is a powerful Python SQL toolkit and Object Relational Mapper (ORM) that is widely used by the Python community.

  • No Migration files - All migrations are setup in the file of the models directory. Personally, rails has it right, with it's easy to understand migration creation, in my opinion. However, Pylons isn't hard, it's just, well, more.

  • Templating Engines - Instead of ERB, they use Mako, by default. It's not that strange when learning mako, as some of the nomenclature is similar.


Both have their pros and cons. I don't mind Pylons, and I'm going to try and create a project in Pylons, something other then the wiki from their tutorial. I'll be bloging my way through that project, and giving you the usual uncandidness you've been accustomed to. If you want to expand your web framework knowledge past rails, Pylons is a good choice to start with, without the huge learning curve.

Monday, May 18, 2009

Spam Off - Acts_as_Snook Tutorial

You wrote an awesome blog post. You've enabled comments for this awesome blog post, only to find that some crappy spam turnkey operation has hit your post with 1000 cialis ads, and the other wang pill advertisements.

Listen, Comment Spam sucks ass. If you've ever searched for an answer to stopping it, your research points you to one of four ways to stop comment spam traditionally. These are:

  • No comment spam filters at all - Users are allowed to comment willy nilly.

  • Captchas - weird images that look as though your seeing through beer goggles, whose text usually has to be written into a text field to prove your comment is coming from a human.

  • Site Members can comment only - the site's membership, of which you are visiting, are only allowed to comment on stories. I am using that method in my blog, atm.

  • Moderated comments - your honest feedback about a post can only be posted, if a nameless/faceless drone 'approves' your comment worthy of being posted. Doesn't say much for transparency.

While all of these above methods work to keep spam to a minimum, (and really that's all you can hope for i.e., minimal spam), there are glaring flaws in each and everyone one of the above methods. Whether it's accessibility, too cumbersome to keep up with, or too communist, most of these methods have some kind of tradeoff.

Enter Acts_as_snook

From the README:ActsAsSnook is a simple and elegant method of handling comment spam that doesn’t rely on CAPTCHAS or Javascript or external web services. It uses a point based system to detect common traits of comment spam.

The acts_as_snook plugin is a great way to keep spam at a minimum. Rather then asking the user to do anything, acts_as_snook "scores" each comment based on a scoring system by Jonathon Snook. Once the comment has been saved into the database, the comment receives one of three possible spam statuses:

  • Spam - the comment didn't pass the scoring system and will have a status of spam, set in the database.

  • Ham - the comment passes the scoring system and it's status is set to ham in the db.

  • Moderate - the comment is too close to call spam or ham, so it's status is set to moderate and is awaiting moderation.

About the Plugin

If anyone trolls in #rubyonrails, the IRC chatroom, you'll know the author of the acts_as_snook plugin, rsl.

He is also responsible for getting this song in my head, at the time of writing. Bastard.

Tutorial - How to use the Plugin

Don't cut and paste!!! this stupid blogger crap is garbage! So if you want to cut and paste, you'll need to delete the spaces after and before each < or > bracket.

Assumptions - you know how to create a typical blog application that will use embedded comments at the end of each post. I'm assuming that you will have two models Post andComment. Before you begin, get a working Post model ready, as this tutorial is only about adding a Comment model that uses acts_as_snook. Lastly, you'll want to make it prettier once your done these steps, so that is up to you do after, post modem.

  1. You have a working Post model, right???

    Get your Post model working how you want it to work. The inner workings aren't important for this tutorial.

  2. Generate a Comments Model and a Post Migration

    We'll use the default settings in acts_as_snook, so that means we need our database to house these Comments table columns as outlined below.

    script/generate rspec_scaffold Comment author:string email:string url:string body:text spam_status:string post_id:integer

    Since we want to display how many GOOD comments we have (i.e, the ham), acts_as_snook will run a counter cache for each Post's ham comments. All you have to create the following migration file and add the migration column information to it:

    script/generate migration AddHamCountToPost

    In your new migration file add the following:

    class AddHamCountToPost < ActiveRecord::Migration
    def self.up
    add_column :posts, :ham_comments_count, :integer, :default => 0

    def self.down
    remove_column :posts, :ham_comments_count

  3. Run Migration with
    rake db:migrate

  4. Add Acts_as_Snook functionality

    First make sure Post has_many Comments and Comments belongs_to Post.

    Next add this to your Comment.rb file
    Damn, that was easy.

  5. Fix the Comment views

    Right now, your views are set to show all comments, that is not good. Let's make your views shine! So in your Post#show view, here is what i've done (since i show my comments at the end of each blog post, my @comments= @post.comments. If you don't understand that, read up on associations in the rails guide). I'll explain the code further afterwards.

    < h1 >Comments< / h1 >
    < % unless @comments.blank? %>
    < % @comments.ham.each do |comment| %>
    < p >
    < % if comment.url.blank? %>
    < %= %>
    < % else %>
    < %= link_to, comment.url %>
    < % end %>
    says:< br/ >
    < %= comment.body %>< /p>
    < % end %>
    < % else %>
    < p>Be the first person to comment!< /p>
    < % end %>

    Simply put, we only want to show the ham(the good comments) and not the spam(shitty comments). So we iterate through each ham comment, using the acts_as_snook supplied method ham.

    The rest of this code, just shows the comment in a certain way that i wanted it to appear, your mileage will vary.

  6. Showing a Comment Count

    One last little touch, is showing your readers how many comments each post has. I put this information on the Post#index page, usually. Here's one way you can implement a count for all ham comments.
    < % @posts.each do |post| % >
    < h2 >< %= link_to post.title, post % > ::~ < %= pluralize post.ham_comments_count, "Comment" % >< /h2 >
    < p >< %= truncate post.body, 25 % >< /p >
    < % end % >

    Notice again, we iterate through the posts and for each post, we add their ham_comments_count.


Acts_as_snook gives us a lot of easy to use methods, which i'll write more about in Acts_as_Snook part 2, which will include a moderation area for administrators. Hopefully Acts_as_snook will take care of your comment spam nightmares, while giving you more time to sing, same as it ever was. Letting the days go by....

Tuesday, May 5, 2009

Upcoming update to Theme support plugin

I'm updating the theme support plugin to work with 2.3.2 now. jystewart has done a tonne of work with it, but his plugin doesn't yet use the helpers, which my version does.

We'll either combine forks or go our separate ways depending on how things play out, so stay tuned!!!

Here is the theme support repo on github. Follow the fork link to jystewart's if interested.

UPDATE - Use jystewart's github theme support for 2.3.2 and mine for 2.2.2 rails app

For some stupid reason the core guys flip flopped on a code insertion that screwed up 2.2.2 and I had to fix it so that the helpers worked in rails 2.2.2.

However, now that they reverted to code from 2.1.2 in 2.3.2, the old helper methods, which the jystewart version didn't touch, work fine. So rather then mess with it, it's easier just to use jystwart's version.

Lastly, in rails 3.0 i think it will revert again, so stay tuned.

Friday, May 1, 2009

When in doubt... Factory it out...

Boy did i have a doozy of a day trying to get some basic tests to pass, after i added some validations to a basic rspec_scaffold. Using the barebones tests, adding the validates_presence_of and a validates_uniqueness_of both borked the test... which was fine, i expected that.

What i didn't expect was that when i commented out both validations, my create test spec method would still work. in essence, it didn't. It could have been something i did, whatever. I fixed the failing tests by simply switching to Factories, instead of fixtures, or whatever the base rspec scaffold would use in a model test.

If you are getting some weird errors, simply try to use factories instead. Try out Factory Girl by Thoughtbot for an example of one that I can say works. haven't tried too hard to get machinist to work yet, but heard good things too.

Saturday, April 25, 2009

Rails Template FTW

Boy oh boy, rails templates kick ass. I just made a template that has everything i need to start an user authenticated monthly subscription rspec app.

What's this template got that i ain't got?

Other then charisma and a good sense of style, it has

  • Restful_authentication w/ AASM && will_paginate - creates your User and Session automatically
  • Active_Merchant - sets you up for adding monthly subscription code
  • Subdomain_fu - allows for easy account creation with subdomains.
  • Testing: Rspec, Cucumber, machinist, faker, factory_girl too
  • rspec scaffold an account model to begin your journey

Rails templates are good to get you going but they are just a starting point, you still need to add certain bits of code to make stuff work, like
require 'aasm'
to your config/environment.rb file.

How to Rock the Template

Type the following into your console
rails -m app_name_here -d postgresql
Remember that the code above will create a postgres based rails app, so supply whatever DB flag you want, mysql, couchdb etc, and replace app_name_here with whatever you want to call you app.

Wednesday, April 15, 2009

Rails Visionaries - Gems/Plugins Top Contributors

The following is a list of the people/companies whom i feel are leading the pack when it comes to the most useful gems and/or plugins. My criteria is that the gem/plugins are almost KEY to any rails app that needs them, and that this person/company has more then ONE key gem/plugin. FYI - I left out DHH, he gets enough accolades. Let's begin

  1. Technoweenie github repo - Where would a lot of rails apps be without restful_authentication and attachment_fu, just to start. When you add in Acts_as_paranoid and his work with Mephisto, we owe this dude a big thanks for making components of what we do in rails easier and more efficient.

  2. thoughtbot github repo - This company keeps pumping out hit after plugin/gem hit. In the field of testing, they help simplify our testing needs by putting out shoulda and factory girl. In the authentication field, they gave us clearance and paperclip. In the error notification field, they offer hoptoad, (which is rad).

  3. mbleigh github repo - Now mbleigh is a dude that should get mad props, and you should get to know his work, if you aren't familiar yet with him. Essential gems/plugins such as subdomain_fu and twitter_auth are just two of his current 24 projects he has on his repo. When you add acts_as_taggable_on and his ubercool uberkit (for easier form and menu creation), you realize how truly original his work is to our community.

  4. Phusion github repo - Passenger makes all production app serving easier. Back in the day, it was mongrel that made things easier... things keep evolving. However, i can't see how it could get any easier beyond Passenger, which makes setting up your slice/VPS extremely easy. And from their website they describe the Ruby Enterprise Edition as Transparently improve scalability and efficiency of Ruby on Rails web applications.

  5. Shopify github repo - If you handle anything to do with ecommerce you must bow at the generosity of the shopify folks. You have active_merchant, active_fulfillment and active_shipping. easy enough to use, powerful and well thoughtout and maintained.

Honourable Mention

There is no question to the visionary impact that these individuals have made to the rails community and furthering it's progress. In the spirit of this post however, these luminaries have given us fantastic testing apps, while this post was looking at those who have given us more then just one type of gem/plugin.

  • aslakhellesoy github repo - Cucumber is making BDD testing easier for everyone. A killer gem that makes learning testing palatable.

  • dchelimsky github repo - RSpec. enough said. (I do realize it is a team of core dev's who create this, but for clarity purposes, his name is usually at the forfront of any rspec conversation).

  • thinking_sphinx github and acts_as_ferret github - Good search plugins and gems. You are either a Ferret guy or a Sphinx guy.

Well that is the list. Enjoy

Tuesday, April 14, 2009

Struggles with webrat via cucumber

I know that this will end up being pebkac... but it still is annoying

So i have a problem. webrat is not acting how i thought it was supposed to. Ryan Bate's railscast on cucumber made this shit look so easy. And for the most part, it is.

However, when you go beyond what he had in his railscast - beginning cucumber, webrat takes me off the rails very fast.

to the Code...

all i wanted to do was select my choice from a dropdown menu. According to webrat/cucumber webrat_steps.rb file it should be
I select "option" from "field"

So in my scenario, i used the field name "tweet[style_id]" and the option "story".
I select "story" from "tweet[style-id]"
You may be wondering what that tweet[ ] business is all about, well that was the only way my scenario would go green, is if i used the label name in that style of code. Since i am not using a symbol in my
f.label :body, "I want to show this text" if you were simply using f.label :body, you wouldn't need the tweet[ ] syntax.


i did find this ruby forum post, however he simply had the wrong description text. Since my text is one word, and i copied and pasted from the view source code, i don't think that is my problemo. Maybe i should try using the label field without the quotes?

Friday, April 3, 2009

Weekend Rails Challenge #1

Thanks for participating in the first ever Weekend Rails Challenge.

The rules are simple for this challenge:
You have 48 hours to code a "For-Profit" based rails app using the twitter api. Also your app must have a colour scheme revolving around the following hex code #7C6D8A. Lastly you app Must be online and useable, hosted by yourself of course on your vps slice or node.
The challenge will run for a month and a winner will be chosen based on the app which gains the best combined score based on five different criterion.

Judging the winner

The winning app will have demonstrated the best TOTAL score of the following criteria:

  • (20%) Quality of Code - Following the rails mantra of DRY and readability, a mark will be given to you based on how well your code follows these coding principles. Usually you would test along the way but we've decided that in 48 hours that is not mandatory for this challenge.

  • (20%) Site Popularity - The site with the highest Alexa ranking at the end of the month will receive a full 20 points, 18 for the second best rank, down to 12 for the worst ranked site. 5 bonus points are rewarded for a mention in twitters sidebar menu (located below the profile of a twitter user)

  • (10%) Site Look and (10%) User Interface/Interaction - The site with the best looking and most functional user interface will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking

  • (20%) Revenue made in a month - The site with the most revenue made during the month will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking.

  • (20%) Most Creative Use of the given rules - An app that demonstrates the most creative and functional use of the given rules will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking.

How will the scores be judged?

No idea, but i know that we participants will vote and we'll ask someone or a few people from ROR to vote on things like coding, site look and feel and creativity.

Submission Deadline:

We'll report back who ends up in the final challenge eventually, but if you want to enter, you MUST post a comment below regarding the purpose or solution you came up with for your app by 12 noon, as of you own time zone, on Saturday April 4th.

Good Luck Challengers

Best of luck and hey who knows... you could get a great money making app out of it. At worst, you made some new friendships and had a good weekend coding and learning.

Saturday, March 14, 2009

Creating a Rails Plugin - thoughts behind Active_Affiliate

I'm about to launch a new whizbang plugin. Really excited about it as i think it will add something to the Rails community and show that i have learned SOMETHING over these last 18 months.

I just wanted to document the thought process for this plugin, without talking about the code. Hopefully you find it interesting, or even helpful

Thought Process

I started with the premise that if you run a successful web app, that charges a membership/account fee, you will need some way to bring in new customers. Affiliate programs are a way to leverage the Internet Marketing initiative and your app.

There really are just two main players in the affiliate space, commission junction and Linkshare. There isn't anything wrong with these programs and chances are you'll need them too, but hosting your own affiliate program and managing it how you want, was a dream i wanted to fulfill.

Since i code in rails, and there was no solution, i created one. Here are some of the features.

  • Affiliate Signup through a route /affiliates

  • Affiliates get their own unique code

  • Primitive banner ad generator that will populate link with their code

  • Affiliate code tracking put in session variables, and saved on customer purchase, through your checkout/signup sheet.

  • Currently, paypal id's are needed so the user can get paid.

  • Reporting for both the Affiliates and App Management.

I'll be updating active_affiliate on github as features are implemented.

Thursday, March 12, 2009

Weird script/generate scaffold behaviour

As always feel free to correct me if i'm wrong, but here is some wacky behaviour i got when i used the following code to generate scaffolding from rails 2.2.2 core (i.e., no plugins or scaffolding generator plugins at all)

script/generate scaffold affiliate name:string user_id:integer

What was happening to my code was views not being found. restful paths not being found, even when i triple checked my routes file. To solve this i simply reran the code with a capital letter for the model name, as shown below.

What should the code be??

script/generate scaffold Affiliate name:string user_id:integer

Treat scaffold like every model is always CamelCase

By that i mean no matter what the name of your model is going to be always Capitalize the main words for that model. So single word models like Ass, Border, User are good. Never start with a lowercase ass, border or user.

This is just a rule i follow, as i've yet to see it let me down. It might just have been a momentary blip we all experience in our coding life, however capitalized models have never shown me that blip to date, so i'll run with it!

Monday, March 9, 2009

Rails Testing Confessions

Father, My name is pjammer and i have confession to make. I've made 4 web apps and didn't test one of them, in a rails sense.

That's right. Not one of my apps were tested using shoulda, coulda, woulda. Rspec was just a figment of someone's imagination, when i launched my apps, cause it sure wasn't in my mind's eye. Factory girl is a movie about some broad from the 60's and Object daddy just sounds creepy

Let me repent for my testing sins!!!

Father, I'm here today to repent for the sins of not testing my apps. I really want to learn

Learning about testing is like searching google for a future thought. Lots of ideas you can get out of it, but nothing that says "HERE IT IS MY SON".

This post won't help you either, but it should give others who want to make a lot of money, teaching other users how to write tests for rails, some kind of "IDEA" for a tell all book about testing.

The Big Idea

Father, why hath thou forsaken my learning? Learning Rails was easy... tonnes of help on blog posts, forums, etc... yet when it comes to LEARNING HOW TO TEST, doth hast left that chapter blank in thy bible

Here is what i think someone could make a mint from writing a book that steps a user through building tests from TIT to TAIL.

For instance:

  • What is testing and why it's important
  • There are four facets to testing
    • Functional Tests
    • Unit Tests
    • Integration Tests and
    • Fixtures
  • Take each testing facet above and step through each assertion and when to use each assertion and 5 or 6 real life examples for each.
  • Focus just on Test::Unit, Shoulda, and Machinist & Faker for Functional and Unit Testing, as well as fixtures
  • Lastly, use some cool visual tool like webrat or Selenium

Father, thank you. I will say my 10 hail mary's

In closing god would be happier with a book such as this, as less rails noobs and testing noobs would be praying for this kind of mundane nonesense. Leaving more time to fight the good fight.

Wednesday, February 18, 2009

PostgreSQL on Mac OS X from source, with gem!

This one was a bitch for me. I started with the one click installer from the postgresql website, not worth the time. maybe it worked, but sure as shit didn't appear to work for me.

Steps i took to get PostgreSQL and postgres gem on my macbook (Intel)

I'll source these links later, but basically I:

  1. downloaded the source code from Postgres's site.

  2. Used the following commands
    ./configure \
    > --with-includes=/usr/local/include \
    > --with-libraries=/usr/local/lib
    sudo make install

  3. put it into my $PATH directory (so annoying when it's not there)
  4. FOR THE RUBY GEM I used the following code because i'm on a fricking intel mac thanks to acts_as_blog
    sudo env ARCHFLAGS='-arch i386' gem install postgres -- \
    --with-pgsql-lib-dir=/Library/PostgreSQL/lib \

Hopefully this saves someone some time and heartache!

There is far too much to detail here...

Acts_as_blog post has everything you need. it should work for you. if it doesn't you need to look at creating your db user through psql.

Friday, February 6, 2009

My list of items to finish before the big launch.

I just thought i'd post the items that i need to finish before i launch. As i cross each one off of the list, i'll report back on how i tackled each problem. Some answers may take a whole post.

The List

  • figure out up to 7 day activation period for Accounts. Not a free trial but You have up to 7 days to activate.

  • add site for sale area.
  • Completed Ranks. Moderator roles is a feature i'll add later.
    Add forum roles to forum and make extendible if needed.

  • add user google adsense code section.

  • When new plugins are added, I'll need to create an instantiator based on the menu items the user has selected. #how to handle old members based on a new plugin being added? How do other sites handle it?

  • add body[:url] to mailer based on the current url they are on.

  • look into using AASM which creates a state for the accounts based on the presence of profile_id and then the current status of the user, as taken from paypal. (Users can cancel a monthly subscription on paypal, i need to know who is doing what)

Some of this shit may not make sense to you, however you will be able to tweek it to your exact situation.

Sunday, January 25, 2009

How to deploy when Capistrano doesn't work for you.

What happens when Capistrano just doesn't work for you?

Ok, maybe i'm the only one with that problem, but i've tried on three different server providers, linode, gogrid and slicehost. All had the same problem, somehow, someway my user privleges were f!@#cking it up.

When a tutorial i've trusted tells me to put my directory to chown www-data, well, i am going to do that. In order to do this i need to sudo everything, thanks to ubuntu, and it's a best practice i can wrap my feeble mind around.

How to deploy a rails app when Capistrano just ain't working for you.

I've not been able to find one source on the net that showed me simply how to deploy a web app using just git, and ssh. So i'm open to better ways, however, i've tested this way for the last 3 weeks and am pretty happy with it.


You are using

  • GIT locally and on your server
  • a full Rails setup (I'm using passanger)
  • a server that hosts both your git repository and your app
  • you've setup both your app and git repository on that server box too

  • You are also using www-data as the group and user who "owns" the app on the server.
    That is just too much shit to talk about right now.

The code below walks you through what to do AFTER your initial setup of your server and app environment.

  • On my laptop:

  • Make the changes to your app, when every test passes and when you are ready to go to production do the following:

    • git status # on my machine changes appear in red.

    • git add . # notice the dot after the add

    • git status # if you see anything in red that should also be included use the second git commit line below

    • git commit -m "Add your message about what your committing here." #most of the time use this

    • git commit -a -m "Added all files including untracked ones" # Again only use this one if there are files that appear in red and should also be included in your commit.

    • git push # pushes your code to your server.

  • SSH to server, all these commands are done from your server:

    • cd /var/your/directory/to/your/app # e.g, /var/www/myapp

    • sudo git pull #pulls all of your latest changes and merges them into your app. see troubleshooting if something f@#cks up.

    • sudo rake db:migrate RAILS_ENV="production" # and any other things you need to do, like start ferret or whatever.

    • cd ../ # back out of this directory

    • sudo chown -R www-data:www-data myapp #notice that we are changing ownership of the whole myapp directory and everything below it. Passanger loves this.

    • cd myapp/

    • sudo touch tmp/restart.txt # how to restart passanger


Well i spent 2 or 3 days easily, 4 - 8 hours at a time trying to make capistrano work. The process above takes 3 minutes. Someone else can do the math, but in order for this way to be less efficient, i'd have to do some 300 commits before i regret not having capistrano. One day i'll need it to deploy to 100 servers or something but for now, i can live with the process above.

Wednesday, January 21, 2009

theme_support and formatted routes (rss feeds)

Today I was trying to get my web app to allow subdomains to provide an rss feed. it didn't work.

I'll be posting a solution when one is found, however, i'm hoping this wasn't pebkac again.


In your controller, where you are making the rss call, you must render layout false. Here is an example:

format.rss { render :layout => false }
I'll file this one under the learn something new, that is easy, everyday column.

After some investigation, it appears that theme_support plugin doesn't support themed rss feeds, when you enter them in the head section of an html page. I'm working to allow this in the plugin.

Saturday, January 10, 2009

passenger and the case of the non-redirecting account. -solved cause i'm dumb.......

Let me explain what is going on here. In my code I want the user to create an account (from and then, upon successful creation of the account, I want them to redirect to the new account's url, at say

Redirect doesn't happen in Production

I'm using Passenger and Apache on a ubuntu server.

On my dev box: Mongrel from the rails app, the usual script/server stuff

So on dev, it works fine. I get redirect with reckless abandon.

In production, a different story. I get the following error (using safari, yet to try with other browsers...).Safari can’t connect to the server.
Safari can’t open the page “” because it could not connect to the server “”.

Why me? I should say, I can type my new url into the browser, no problem. it works fine, but it's not what I want my user's to have to do.

Did you solve this?

Embarrassingly I had a link to localhost:3000 as my redirect. Ignore this post. it's left as a reminder when i get too fucking cocky.... as a mark on my pride.