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

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.


Updates

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
    make
    sudo make install


  3. put it into my $PATH directory (so annoying when it's not there)
    PATH=$PATH:/usr/local/pgsql/bin
  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 \
    --with-pgsql-include-dir=/Library/PostgreSQL/include


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.