Archive for the 'Ruby on Rails' Category

Engine Yard problems

Saturday, March 6th, 2010

Here I am with yet another proprietary EngineYard problem again. I simply clone an existing application that’s up and running fine and the new cloned environment doesn’t boot. Its giving me this error instead:

/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails/gem_dependency.rb:224:in `specification’: undefined method `version_requirements=’ for # (NoMethodError)

Here’s a recent thread about the same issue:

http://rubyforge.org/tracker/index.php?func=detail&aid=27868&group_id=126&atid=575

Looking into the differences in my ‘cloned’ environment and my actual environment and I see the gems list isn’t even the same. So basically Engine Yard’s clone command doesn’t actually clone the environment at all. It just took my old apps and tried to copy and paste everything onto a newly configured environment which obviously doesn’t work.

My original environment gems:

abstract (1.0.0)
actionmailer (2.3.5, 2.3.3, 2.2.2, 1.3.6)
actionpack (2.3.5, 2.3.3, 2.2.2, 1.13.6)
actionwebservice (1.2.6)
activerecord (2.3.5, 2.3.3, 2.2.2, 1.15.6)
activeresource (2.3.5, 2.3.3, 2.2.2)
activesupport (2.3.5, 2.3.3, 2.2.2, 1.4.4)
addressable (2.1.1)
aws-s3 (0.6.2)
builder (2.1.2)
daemons (1.0.10)
erubis (2.6.2)
eventmachine (0.12.6)
extlib (0.9.9)
eyrubygems (0.0.2)
facter (1.5.2)
fastercsv (1.5.1)
fastthread (1.0.7)
ferret (0.11.6)
gem_plugin (0.2.3)
hpricot (0.8.2, 0.8.1)
igrigorik-em-http-request (0.1.5)
json (1.1.3)
mime-types (1.16)
mixlib-cli (1.0.4)
mixlib-config (1.0.12)
mixlib-log (1.0.3)
mongrel (1.1.5.1)
mongrel_cluster (1.0.5)
ohai (0.2.0)
open4 (0.9.6)
rack (1.0.1, 0.4.0)
rails (2.3.5, 2.3.3, 2.2.2, 1.2.6)
rake (0.8.3)
rest-client (1.3.1, 0.9.2)
right_aws (1.10.0)
right_http_connection (1.2.4)
rmagick (2.8.0)
ruby-openid (2.1.2)
rubyforge (1.0.3)
sparklines (0.5.2)
stomp (1.0.6)
systemu (1.2.0)
will_paginate (2.3.12)
xml-simple (1.0.12)

And the ‘Cloned’ environment gems:

abstract (1.0.0)
actionmailer (2.3.3, 2.2.2, 1.3.6)
actionpack (2.3.3, 2.2.2, 1.13.6)
actionwebservice (1.2.6)
activerecord (2.3.3, 2.2.2, 1.15.6)
activeresource (2.3.3, 2.2.2)
activesupport (2.3.3, 2.2.2, 1.4.4)
addressable (2.1.1)
aws-s3 (0.6.2)
builder (2.1.2)
daemons (1.0.10)
erubis (2.6.2)
eventmachine (0.12.6)
extlib (0.9.9)
eyrubygems (0.0.2)
facter (1.5.2)
fastercsv (1.5.1)
fastthread (1.0.7)
ferret (0.11.6)
gem_plugin (0.2.3)
hpricot (0.8.2, 0.8.1)
igrigorik-em-http-request (0.1.5)
json (1.1.3)
mime-types (1.16)
mongrel (1.1.5.1)
mongrel_cluster (1.0.5)
ohai (0.2.0)
open4 (0.9.6)
rack (1.0.1, 0.4.0)
rails (2.3.3, 2.2.2, 1.2.6)
rake (0.8.3)
rest-client (0.9.2)
right_aws (1.10.0)
right_http_connection (1.2.4)
rmagick (2.8.0)
ruby-openid (2.1.2)
rubyforge (1.0.3)
sparklines (0.5.2)
stomp (1.0.6)
will_paginate (2.3.12)
xml-simple (1.0.12)

Clearly this new environment isn’t a ‘clone’ at all. You can’t just put feathers in your butt and call yourself a chicken. Don’t call this feature ‘clone’ when its really just recreating everything on a completely different setup if they’ve changed their default environment configuration. It should be called the ‘waste another 4 hours fixing our broken Engine Yard system’ feature. I think its a little more accurate.

Rojo: An easy to install Ruby on Rails CMS

Monday, February 8th, 2010

Rojo is Onomojo’s Ruby on Rails Content Management System. You can find it here:

http://github.com/onomojo/rojo

Today we made some changes to make the initial setup of a Rojo instance easier. The steps to setup a new Rojo instance are clearly detailed in the README. This should help eliminate most of the problems new users were encountering when trying to setup Rojo from scratch. Please let us know if you have any comments or suggestions for improving the setup process.

In the next few weeks, we will be releasing the plugins that we’ve developed for Rojo including a blog, video gallery, photo gallery, and more so stay tuned.

GitHub down yet again

Tuesday, February 2nd, 2010

I am experimenting with a new Engine Yard account today and their Setup basically requires you to have your projects in git. Since the site was from a private svn repos I decided I’d go ahead and signup for a paid Github account so I can host my projects there privately instead of having to setup my own git server. I should have trusted my gut because not more than a few hours later here I am trying to access my Github account and the site is broken again.

Rojo – A Ruby on Rails CMS

Sunday, January 31st, 2010

Rojo logo

We’ve been working on this part time for a while now and I finally decided to just go ahead and release it. Its far from perfect and isn’t what I originally envisioned but it does work and we do use it on a number of sites. Its fairly stable and we have a handful of plugins that I’ll be releasing in the next week or two.

The 2 main motivations for Rojo came from the lacking diversity in Ruby on Rails content management systems. There are a few and some work well but I wasn’t happy with the learning curve with the ones I explored when we initially started this project. It seemed to me that every time I embraced a CMS the CMS ended up determining how I had to write my application. Its simply impossible to craft a CMS that enforces a strict data and programming interface that works for every situation. I didn’t want a content management system that forced me to write my tables one way or another or forced me to communicate with the CMS in certain ways. In short, I really just wanted a simple core that I could easily extend in any way I needed without having to conform to any standard imposed by the CMS.

You can check out the Rojo code here: http://github.com/onomojo/rojo

Rails threading with Spawn plugin

Tuesday, December 8th, 2009

My previous post was about using Thread in Rails which simply doesn’t work properly when you’re doing anything with ActiveRecord despite what anyone else is claiming.

This post will focus on my second attempt at a solution to intra-request threading in Rails. Basically, I have a Rails app where I want to run multiple computations at the same time. Since I had problems with Ruby’s native Thread method previously, I had no intention of going down that route again. I decided to try out the Spawn plugin.

Spawn was able to successfully segregate my multiple threads, or forks in my case. This got around the MySQL errors I reported in my previous post but it created a whole new set of problems all its own.

The first problem I had was that the spawn forks I was creating weren’t able to communicate their changes back to the main Rails request. I was creating forks and they were running fine and even saving data via ActiveRecord. I could confirm this via the console. The problem was that I need to know what data was being written by the spawn forks inside of the main Rails request. It was as if the main Rails request didn’t even know that something new was written to the database. I was able to get around this by forcing a reload from the database on the object I was trying to get association data from.

No big deal and it seems to make sense to do that anyway. That’s not where the real problem occurs though. After I got past that I realized that since each fork was essentially using a ‘copy’ of the database and not actually live connections that the data validations randomly failed. Basically if two forks are writing data to the database at the same time when there is a validates_uniqueness on the data. They both write to the database and both actually pass validation. The result is a database full of incorrect data which should have never passed the validation. I’m still not sure if that’s a problem with Spawn or an inherent problem with ActiveRecord’s connection pool.

Why the open source community needs to rethink migrating to Github

Tuesday, November 24th, 2009

Here I am yet again at a standstill because the Rails gems have mostly all migrated to Github and the site is down. This is the second or third time this year that Github has messed up and caused me to stop dead in my tracks because I couldn’t access the gems I needed. I can’t even remember the last time my subversion repository went down. This is exactly the reason I thought the Rails community was crazy for mass migrating to Github. Its just not a good idea to have 1 centralized location responsible for all your gems. Especially when they go down all the time. What we need is a company with experience maintaining quality uptime to manage this site in the short term and in the long term we need a more distributed mirror type system to roll-over when Github dies again.

Github down again

Github down again

AOL support for Rails contacts gem

Wednesday, November 18th, 2009

I’ve just finished adding AOL support to the Rails contacts gem. You can check out my code here: http://github.com/onomojo/contacts-gem

Until this is officially added to the contacts gem release, you’ll need to create a RAILS_ROOT/lib/contacts/aol.rb file with the following contents:

class Hash
def to_query_string
u = ERB::Util.method(:u)
map { |k, v|
u.call(k) + “=” + u.call(v)
}.join(“&”)
end
end

class Contacts
require ‘hpricot’
class Aol < Base
URL = "http://www.aol.com/"
LOGIN_URL = "https://my.screenname.aol.com/_cqr/login/login.psp"
LOGIN_REFERER_URL = "http://webmail.aol.com/"
LOGIN_REFERER_PATH = "sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=0&siteState=ver%3a4|rt%3aSTANDARD|ac%3aWS|at%3aSNS|ld%3awebmail.aol.com|uv%3aAOL|lc%3aen-us|mt%3aAOL|snt%3aScreenName&offerId=mail-second-en-us&seamless=novl&xchk=false"
# http://webmail.aol.com/28878/aim-2/en-us/Suite.aspx
CONTACT_LIST_URL = "http://webmail.aol.com/28878/aim-2/en-us/Lite/ContactList.aspx?folder=Inbox&showUserFolders=False"
CONTACT_LIST_CSV_URL = "http://webmail.aol.com/28878/aim-2/en-us/Lite/ABExport.aspx?command=all"
PROTOCOL_ERROR = "AOL has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts"

def real_connect

postdata = {
"loginId" => login,
“password” => password,
“rememberMe” => “on”,
“_sns_fg_color_” => “”,
“_sns_err_color_” => “”,
“_sns_link_color_” => “”,
“_sns_width_” => “”,
“_sns_height_” => “”,
“offerId” => “mail-second-en-us”,
“_sns_bg_color_” => “”,
“sitedomain” => “sns.webmail.aol.com”,
“regPromoCode” => “”,
“mcState” => “initialized”,
“uitype” => “std”,
“siteId” => “”,
“lang” => “en”,
“locale” => “us”,
“authLev” => “0″,
“siteState” => “ver%3A4%7Crt%3ASTANDARD%7Cac%3AWS%7Cat%3ASNS%7Cld%3Awebmail.aol.com%7Cuv%3AAOL%7Clc%3Aen-us%7Cmt%3AAOL%7Csnt%3AScreenName”,
“isSiteStateEncoded” => “true”,
“use_aam” => “0″,
“seamless” => “novl”,
“aolsubmit” => CGI.escape(“Sign In”),
“idType” => “SN”,
“usrd” => “4222992″,
“doSSL” => “”,
“redirType” => “”,
“xchk” => “false”
}

# Get this cookie and stick it in the form to confirm to Aol that your cookies work
data, resp, cookies, forward = get(URL)
postdata["stips"] = cookie_hash_from_string(cookies)["stips"]
postdata["tst"] = cookie_hash_from_string(cookies)["tst"]

data, resp, cookies, forward, old_url = get(LOGIN_REFERER_URL, cookies) + [URL]
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

doc = Hpricot(data)
(doc/:input).each do |input|
postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == “usrd”
end
# parse data for
and add it to the postdata

postdata["SNS_SC"] = cookie_hash_from_string(cookies)["SNS_SC"]
postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"]
postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"]

data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]

until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

if data.index(“Invalid Screen Name or Password.”)
raise AuthenticationError, “Username and password do not match”
elsif data.index(“Required field must not be blank”)
raise AuthenticationError, “Login and password must not be blank”
elsif data.index(“errormsg_0_logincaptcha”)
raise AuthenticationError, “Captcha error”
elsif data.index(“Invalid request”)
raise ConnectionError, PROTOCOL_ERROR
elsif cookies == “”
raise ConnectionError, PROTOCOL_ERROR
end

@cookies = cookies
end

def contacts
postdata = {
“file” => ‘contacts’,
“fileType” => ‘csv’
}

return @contacts if @contacts
if connected?
data, resp, @cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]

until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end

# parse data and grab
doc = Hpricot(data)
(doc/:input).each do |input|
postdata["user"] = input.attributes["value"] if input.attributes["name"] == “user”
end

data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]

parse data
end
end
private

def parse(data, options={})
data = CSV.parse(data)
col_names = data.shift
@contacts = data.map do |person|
["#{person[0]} #{person[1]}”, person[4]] unless person[4].empty?
end.compact
end
end

TYPES[:aol] = Aol
end

I’ve submitted the source to the authors so it should be added in the next few weeks.

Google is better than Bing for programming related searches

Friday, November 13th, 2009

I’ve been writing a lot about how great Bing is and made the switch to use Bing regularly but here I am in day 1 with using Bing full time and have run into problems. I am working on a Rails project doing some http requests and screen scraping. Basically, I’m extending the contacts gem to include AOL support. I wanted to see a quick reference to refresh my memory on the get / post syntax in Rails. I search Bing for “rails get http” and the first result is a link to rubyonrails.org. How useless. I search the entire first page and find absolutely nothing related to what I’m looking for. I’m beginning to second guess my previous whole-hearted support of Bing. Its good for general searches but it seems program related searches are crap with Bing. I do the same search in Google and the first result is what I wanted. Just a quick reference of someone using the Ruby get method. I tried a few other searches like ‘rails contacts gem’ and Bing doesn’t really give me much to work with in the results. I did have to dig down to the 8th result with Google but the Rails contacts gem project page is at least on the first page of the search results. Google wins when it comes to programming related searches in my opinion. Time for me to switch back to Google for the time being.

The World’s Oyster screencast

Saturday, September 5th, 2009

Here is Micah Friedline with another screencast. This time it’s about The World’s Oyster, a self-updating address book. Stay in touch with friends, business contacts, and more with the easy to use address book that keeps itself updated as you move.

Webster’s Classroom screencast

Saturday, September 5th, 2009

Here is a screencast our account manager, Micah Friedlin, made introducing you to Webster’s Classroom. Webster’s Classroom enables teachers to create free classroom webpages. We just recently upgraded the site to include some new features including password protection, classroom archiving, file dropbox, and more. There were numerous bug fixes and security enhancements made as well.