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

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.