Archive for the ‘Ruby on Rails’ Category

Ruby + Rails Stops Responding on Windows

A friend ran into a bug that I had already conquered. I figure that if we both have the issue, other people might also.

Randomly, Rails (Ruby) will just crash. Most of the time it happened while the assets are being served. After some research I was able to figure out that there was a ton of lines being written to the log file. It turns out that there’s some weird bug, either with WEBrick or Ruby itself that ends up crashing the server when writing information to the log file.

You can disable logging, but that’s a pretty big hindrance. My solution was to install thin server (which is very similar to WEBrick but lightweight.

Here’s what you’re going to have to do:

Update your gemfile:

group :development, :test do
  gem 'eventmachine', '1.0.0.beta.4.1', :platforms => [:mswin, :mingw]
  gem 'thin'
end

There’s tons of issues with event machine installing on windows, so make sure you’re using that exact version above. Run bundle install. And instead of running “rails s”, run “thin start” to get your server running.

The worst part about this bug is that it can easily take you down a rabbit hole. Your error might be on a jquery line, or a css line (whatever asset is being served up). Some of the key things that I do know:

This happens with Ruby 1.9.2
This happens with Rails > 3.0 (which makes me think it’s more a Ruby issue)

Windows will produce these errors (hard crash of Ruby):
Ruby Interpreter (CUI) 1.9.2p290 [i386-mingw32] has stopped working
Ruby Interpreter (CUI) 1.9.2p320 [i386-mingw32] has stopped working

***Update I’m running Ruby 1.9.3p125 and haven’t hit this issue yet using WEBrick. This might be an alternative solution instead of using thin server.

***Update If you’re working with people using Linux/Mac, something like this might be more suitable. It will ignore these if you’re not on Windows:

# le windows
platforms :mswin, :mingw do
  gem 'eventmachine', '1.0.0.beta.4.1'
  gem 'thin'
end

Thanks,
Ry

Build gems that require native extensions on Windows – Install gems in Windows with builds tools via MinGW

Ever get this error when either trying to install a gem, or running a bundle update (someone’s updated the gemfile)?

Fetching: linecache19-0.5.12.gem (100%)
ERROR: Error installing linecache19:
The ‘linecache19′ native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit from ‘http://rubyinstaller.org/downloads’ and follow the instructions at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’

Going to those links and setting everything up is way to much effort. Here’s a quick way to get everything working. We’re going to use MinGW (Minimalist GNU for Windows) to compile our gems.

Head over to http://www.mingw.org/wiki/Getting_Started and read under “Graphical User Interface Installer” (since we love our GUI’s :D). Don’t let the age of that post (2007) scare you off. MinGW is kept up to date. Here’s a direct link for download. Get the latest version. As of writing I’m using mingw-get-inst-20110530.exe.

Run the .exe, click Next, Next, Make sure “Use pre-packaged repository catalogs” is selected, Select the agreement, I use the default C:\MinGW on the next step, Next on the start menu, I use the following:

  • C++ Compiler
  • ObjC Compiler
  • MSYS Basic System
  • MinGW Developer ToolKit

Click Next and a dos window will popup doing it’s magic. Click Finish once it’s done.

Now click Start -> All Programs -> MinGW -> MinGW Shell

Once the shell is open punch in “gem install linecache19″ and you get this beautiful output:

$ gem install linecache19
Building native extensions. This could take a while…
Successfully installed linecache19-0.5.12
1 gem installed
Installing ri documentation for linecache19-0.5.12…
Installing RDoc documentation for linecache19-0.5.12…

Now you can install gems that have native extensions! And you have a new linux style environment to play around with!

You now have a new linux shell to add to your arsenal. There’s also a way to add MinGW to your path so you don’t have to run the MinGW shell, but I personally like to keep my path clean.

This should work for Windows XP, Windows Vista and Windows 7. 32 & 64 bit.

Error installing redcar? Install Java!

Are you receiving this redcar error?

Successfully installed redcar-0.11
1 gem installed
Installing ri documentation for redcar-0.11…
Installing RDoc documentation for redcar-0.11…

C:\Users\Owner\Desktop\Console2>redcar install
Redcar 0.11 ( i386-mingw32 )
found latest XULRunner release version: 1.9.2.16
Downloading >10MB of binary assets. This may take a while the first time.
Precaching textmate bundles…
java -Xbootclasspath/a:”C:/Users/Owner/.redcar/assets/jruby-complete-1.5.3.jar” -Dfile.encoding=UTF8 -Xmx320m -Xss1024k -Djruby.memory.max=320m -Djruby.stack.max=1024k org.jruby.Main “C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/bin/redcar” –no-sub-jruby –ignore-stdin –no-gui –compute-textmate-cache-and-quit –multiple-instance –start-time=1302709191
C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/lib/redcar/installer.rb:140:in “’: No such file or directory – java -Xbootclasspath/a:”C:/Users/Owner/.redcar/assets/jruby-complete-1.5.3.jar” -Dfile.encoding=UTF8 -Xmx320m -Xss1024k -Djruby.memory.max=320m -Djruby.stack.max=1024k org.jruby.Main “C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/bin/redcar” –no-sub-jruby –ignore-stdin –no-gui –compute-textmate-cache-and-quit –multiple-instance –start-time=1302709191 (Errno::ENOENT)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/lib/redcar/installer.rb:140:in `block in precache_textmate_bundles’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/lib/redcar/runner.rb:80:in `construct_command’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/lib/redcar/installer.rb:139:in `precache_textmate_bundles’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/lib/redcar/installer.rb:26:in `install’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/bin/redcar:25:in `
from C:/Ruby192/bin/redcar:19:in `load’

Install java

I got this error after setting up a brand new virtual machine which didn’t have java on it. Once I installed java I was good to go :)

C:\Users\Owner\Desktop\Console2>redcar install
Redcar 0.11 ( i386-mingw32 )
found latest XULRunner release version: 1.9.2.16
Downloading >10MB of binary assets. This may take a while the first time.
Precaching textmate bundles…
java -client -Xbootclasspath/a:”C:/Users/Owner/.redcar/assets/jruby-complete-1.5.3.jar” -Dfile.encoding=UTF8 -Xmx320m -Xss1024k -Djruby.memory.max=320m -Djruby.stack.max=1024k org.jruby.Main “C:/Ruby192/lib/ruby/gems/1.9.1/gems/redcar-0.11/bin/redcar” –no-sub-jruby –ignore-stdin –no-gui –compute-textmate-cache-and-quit –multiple-instance –start-time=1302747689

Install instructions here:

https://github.com/redcar/redcar/wiki/installation

Creating Alertzy.com – #Apps4Edmonton

This is abit of a read, but I tried to cover everything. I’m going to create this is a timeline format. Hopefully I don’t fail.

July 22/2010
The Meetup
At the beginning of July I received a message over Steam (while dominating as a Sniper in TF2 *flex*) asking if I wanted to take part in an app making contest for the City of Edmonton via Greg. Since most of my other friends were either to busy doing other things, or still in school I leapt at the chance to build *something*.

I had looked into the deadline for the application at the City of Edmonton and saw that it was August 27, 2010. That would give us roughly a month to build an app, test it, and release it out to the public.

At this point we hung out and decided our roles, Ben and myself as developers, and Greg and the graphics designer. We were to break out, come up with some ideas and meet in a few days.

July 25/2010
Decisions, Decisions
First things first. We started throwing out ideas over the table. We wanted to use something from the open data catalog that the City of Edmonton has graciously provided.

Ben had built a prototype of an ETS map that would’ve allowed us to do many things with the ETS data. There was tons of data on ETS, but we new that market was going to be saturated and wanted to try and think outside the box. We also wanted something that everyone could use (not platform specific ie. iPhone, Android). We decided pretty much everyone has a cellphone now (prove me wrong!).

I had taken inventory of everything that was on the site (that I found might pertain to our app) and came up with the idea of alerting people of garbage day via text. With the team building off of this idea, it slowly morphed into a full, real-time alerting system with many features (not just garbage day anymore). We had loads of data to provide alerts on. Garbage days, soccer field closures and many others.

Data thoughts

Analyzing City of Edmonton

The room was alive with ideas and how we could implement it. But it all came to a full stop once we realized the amount of $$$ it costs for a short code. Upwards of 500$ a month (short codes must be used for business, you couldn’t buy a phone from a cellphone company and use that phone number. If i’m not mistaken it’s against the TOS).

We thought the idea was dead right there.. But Ben had a plan! He has a friend who owns Direct Text Marketing. And thought we might be able to get some sponsored texts… We put this thought on hold for now (until Ben heard word from his friend) and moved on to the next topic…

Watch your Language!
Ben being a pHp developer, and myself being a .NET/COBOL developer didn’t help things. I’ve always declared that I hate Ruby on Rails. I just didn’t get MVC, or the magical ninja helpers that Ruby on Rails provides, on my first attempt with RoR. But, we needed a language that would be common to both of us. Ruby on Rails it was! For the next week, we’d be learning Ruby on Rails.

It was a little crazy, we had a month to learn a new framework, and a new language. But we were down for a challenge.

July 27/2010
Good news everyone…
Ben spread the news to Greg and myself that the text messaging with Direct Text Marketing was a “go!” and we had a sponsor.

August 1/2010
The Tools
We knew we needed some tools for this, so we setup Dropbox for our non source code files (images, word docs, etc.), github for our source code (12ish $ a month for an awesome remote repository) and we used Cacoo for our design documents, web layouts, and over all workflow.

We both started with Rad Rails 2 which was the worst mistake of our lives. After banging our heads against the walls, we changed up our development tools. Ben moved over to Textmate for his Mac and I moved over to Aptana Studio 3 Beta which basically copied Textmate (but it’s for Windows!) and has the bash console in the program. I also tried out E Text Editor, but I found it to be a terrible clone of Textmate (the tabbing system didn’t even work properly for me).

E Text Editor Fails

E Text Editor Fails. Half Tabs!?

August 4/2010
What’s in a name?
2 hours. 2… long… hours. That’s how long we sat around thinking of names, checking them against a who is database, and *face palming* whenever we had a good name, and the .com was taken. We came up with a few names and wrote them on our white board and got up to go grab some donairs. Greg went to go get ready, and Ben and I were still coming up with ideas. I was determined to get a Z in our name (Z’s are awesome. I’m gonna name my kid Zen, I swear. Boy OR girl). Anyhow, I blurted out “Alertzy!” In a greek kinda voice, and we added it to the board. We chowed down on our hard earned donairs and picked the name Alertzy an hour later.

Alertzy was added to facebook and twitter on this day also.

August 9/2010
Garbage data madness
At this point Ben and I were pretty much through the rails tutorial that we were using to learn Ruby on Rails (with the addition to some other books I had).

Ryan on Rails Books

Ruby on Rails Books

We noticed that the open data was kind of weird and didn’t match up, we ended up figuring out what was wrong and synced the data up. We fired an email off to the open data at OpenData@edmonton.ca and they fixed it up for anyone else that would be using this. After the competition closed, we noticed that @MarkBennett also had the same problem.

We had been coding for a few days now, and everything was starting to come together.

August 13/2010
It works!
Ben sent out an email with a full test of the Alertzy backend. It worked! Hurrah! Greg also had some great images setup for us to build a layout off of.

Many many lines of code and photoshopping was done during this time. I won’t paste the technical details here, as Ben and I plan to post some technical details of the project at a later date. Ben currently has a few articles at of mice and pen.

August 20/2010
Hosting Gongshow
With all of the graphics applied and Alertzy version 1.0 being done we weren’t quite sure who was the best host, or who to go with. We ended up going with hostingrails.com, but then after a horrible hosting experience, we ended up moving over to slicehost.

Ben spent many of many hours getting the server up and running. We currently use deprec + Capistrano to deploy our application. And for the record, the documentation on the internet was quite poor. I’m sure Ben will blog about this sooner or later.

August 25/2010
We’re Live!
The site went live on slicehost providing garbage day text message reminders, along with field closure text messages.

Alertzy goes Live!

Alertzy goes Live!

Current day, August 31,2010
Thoughts on Apps 4 Edmonton
I think the City of Edmonton was smart to have a competition like this. They provided incentive, data for us to work with, support on that data, and a platform for users to submit ideas, what more could a developer want?

The only concern I would have as a developer would be that the datasets stay up to date, and in the same format. That goes for all cities using the open data catalog.

Thoughts on Alertzy’s business viability
Can Alertzy survive in the market? Absolutely.
We’ve built Alertzy with the ability to scale, use other cities open data catalogs, have a business plan on how to create revenue, and currently spend a very minor amount to host the website thanks to our sponsor.

As the cellphone world expands, we plan to be the #1 alerting system in Canada due to cross platform capability.

Did I mention we plan to roll out email alerts in the future? No more adding items to GMail or Outlook, the alert will be emailed to you directly.

The Team
This wouldn’t have been possible without teamwork and dedication. Greg was off working in Toronto putting in time designing buttons (which we later scraped, sorry Greg :( ), Ben spent his whole weekend fixing the slicehost VPS to allow us to deploy easily and built an awesome garbage map zone pinpointing system while I worked on the verification system.

Whenever problems came up we’d band together and “war room” as Ben would call it. Figure out a strategy and execute the plan. We ran into many problems, but we managed to put our heads together and figure them out.

Shameful Plug
At this point I’ll throw out a shameful plug. If you want to be alerted of Edmonton’s field closures, or are tired of missing garbage day, sign up at Alertzy. If you’d like to support our development, show us some love and vote for us at Apps 4 Edmonton.

Redirect (Refresh) your current page

I’m not sure why I was unable to find this out on the internet, but here’s the simple piece of code you need in your controller to refresh your page:

[ruby light="true"]current_user.verified = true
current_user.save
flash[:notice] = "You’re verified!"
#Redirect/Refresh
redirect_to :back[/ruby]

I call this a refresh, but technically we’re just going back (to where we came from).

Shout out to Ben for finding it!

Return top