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

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.

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.


Prerequisites


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




End


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.



Solution


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 www.domain.com) and then, upon successful creation of the account, I want them to redirect to the new account's url, at say account.domain.com.


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 “http://www.example69.com/accounts” because it could not connect to the server “www.example69.com”.

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.

Friday, December 26, 2008

3 reasons to hate your new iphone

As much as I'd like to say I'm 100% happy with my iphone, i must confess that I am not 100% happy with the iphone at all. The post that follows outlines the three reasons why I am not too happy with my iphone:

  1. You MUST jailbreak your iphone, in order to do anything cool with it
  2. Lack of bluetooth functionality when synced to macbook
  3. Apple's general malaise with bending over to the Telco's



In Canada, did you know that you are allowed to tether your iphone to your laptop. It's a selling feature to idiots like me who commute and aren't always at a wireless connection, and the thought of 3G surfing to improve your ruby on rails app got you off, big time.


The one little wee bit of information no one told you, until you shelled out the money and signed the contract, was that unless you jailbreak your iphone, Apple doesn't have a legal app to allow you to connect via bluetooth to your laptop. It's this lack of Tethering Ability that burnt my britches. I feel it's the man stain on an otherwise pristinely made bed, and i was told to sleep in it.


Now, why must a consumer be forced to jailbreak an iphone, when HE/SHE doesn't want to. I have no desire to do anything like this, nor should a consumer be asked to. He/she gets home, clicks the App Store app and prays to find a tethering app. He/she doesn't. He/she's choice: Jailbreak and risk bricking the phone or surf via Safari on iphone instead of being able to git push from your macbook, which is what i want to do in the first place.


One company had balls. NullRiver. I used their MediaLink app to connect to my PS3. Really good stuff, cause it just works. However, at last check (story Sept 13, 2008) they had their app pulled down from the App store by Apple.


Lack of bluetooth functionality when synced to macbook


Seriously, when you sync up your iphone to your macbook/imac and get that going, did you know that there is nothing you really can do through bluetooth? Maybe in the future, there will be skads of things to do, but generally, you can't do sh!t out of the box, legally.


Users of the "lesser" phones may be shocked to hear that you can't even file transfer via bluetooth from your macbook to your iphone. I believe my first samsung in 2000 had that ability.


Apple's general malaise with bending over to the Telco's


Now i'm a pretty loyal Apple customer. I've got a whole family on imac's or macbooks, a few on iphones, one on AppleTV even. I'm no fanboy who makes the trip to hear Steve Job's speak at MacWorld, I've never read an apple based blog nor do i have an account on ehmac either, but i do troll on the #mac channel often, in IRC. So my heart is with Apple. Linux was too nerdy for me, windows... is... well, windows, so Apple is the only OS that i can tolerate, have fun with and still feel secure. I also like their attitude. Here we are. like it or not, this is Apple. You don't like it, that's fine, there are alternatives out there for you.


So how can a company with this hipster attitude, take it large from a couple of stupid Ma Bell castaway TeleCom companies? Or worse, a Canadian provider!?!?! Grow a set of balls, force these babies to allow their users to surf the 3G network via their laptop, bluetoothily through their iphone. For the amount of people that would do it, and i doubt it would be that many, as most people surf walking in a mall or at a friends house when they say "Hey, look i got an iphone and i can surf for porn from your bathroom!"


So what can be done nerbie69?


I'm glad you asked. Nothing can be done, except get NullRiver's app back onto the AppStore. There is no reason for it not to be there. Also, make sure it is priced around the $29 - $49 mark. People are nothing but cheap and this price point will allow only those who really need it to buy it.


The Telco relationship won't change. Money grubbing won't change, but Apple you can price the NullRiver app accordingly so that you keep your loyal fans happy and still save face with the skidmarks from the Telco world who are trying too desperatley, like an actress getting her 12 face lift, to keep their looks and cool.

Saturday, December 20, 2008

Solved: ApplicationController has been removed from the module tree error.

A copy of ApplicationController has been removed from the module tree but is still active!
You got this error... and now you don't know what to do. Well i can offer a suggestion or two on how to fix it.

Symptoms


You may be trying to update a plugin that is conflicting with ApplicationController. You'll also notice that this error happens when you try to reload the same page, or even move a different view within the same directory. For instance, if you load plugin/index and the try to reload OR go to another link say plugin/new, you get this error.


Hit me nerbie69! Solve my problems


Well dude, you got way too many for me to solve, but this one is on me.


All douchery aside, i solved my error by deleting some of the leftover cruft of having a generator plugin, that i converted into a engines based plugin. github nerbie69/railstat plugin check out the forked project for the current generator based script.


#OLD code
require_dependency 'path_tracker'

class RailStatController < ApplicationController
include PathTracker

before_filter :extract_subdomain
....


#new code notice the difference
class RailStatController < ApplicationController
unloadable
include PathTracker

before_filter :extract_subdomain
...



Since ApplicationController is an unloadable class, we too had to match it's unloadability in our app/controllers directory of our engines based plugin. Also, we don't need the require statement, as you do when you are using a generator plugin, if you are referencing the lib directory. The engines takes care of that for you too.


Wrap it up Johnny!


Ok, engines rock. Also, you can apply this code to any of these stupid errors you might get in the future for other controllers and plugins.


Sources: rails trac from 2006.