Monthly Archive: January 2012

Fixed: ExecJS RuntimeError and FATAL ERROR: v8::Context::New() when deploying Rails to Shared Hosting

I’ve recently been working on setting up a rails app for a site I’m building for one of my side projects.  While I’ve mostly been working on this in my spare time, I decided that it would be important, to one day be able to deploy it to a larger audience (like friends and family). After trying to get rails set up on my old hosting, and being told that Rails 3 wasn’t supported. I recently moved to Vexxhost. Two things enticed me: 1) they’re Canadian; 2) Their hosting is bloody cheap.

So after moving my PHP sites over, I got to work on deploying my currently simple rails app.  And that’s when I hit a problem.

The Problem

ExecJS::RuntimeError in Home#index

Showing /home/jrstarke/apps/___/releases/20120128224905/app/views/layouts/application.html.erb where line #6 raised:

FATAL ERROR: v8::Context::New() V8 is no longer usable (in /home/jrstarke/apps/___/releases/20120128224905/app/assets/javascripts/charities.js.coffee)

Now if you’re finding yourself  in a similar situation, Stop. Take a breath. You’re not very far.

The reason you are finding this is because Rails is clever. The .erb and .js.coffee files in application are compiled, compressed, and this all happens dynamically. They call this the ‘Asset Pipeline’.

The problem is that if you’re shared hosting is anything like Vexxhost (and I imagine most that use cpanel are), their servers in their shared hosting are based on efficiency.  This compiling of assets dynamically takes time and resources, and really, once you’d deployed it to the server, they don’t usually change much (with the exception of a new version, but then that won’t change much either until the next version).

The Solution

It turns out that the solution isn’t all that hard, in fact, most of it I found through a great article on the Ruby on Rails site about The Asset Pipeline – In Production Environments.

The trick is that you essentially need to turn off the asset pipeline. During the dynamic compilation on the fly of assets into a more static compilation. This will still compile your multiple stylesheets and javascript into single files though.

Without further ado, to the solution.

First you need to go into your config/application.rb and disable the application pipeline. You will look for the following line:

config.assets.enabled = true

and turn it to false

config.assets.enabled = false

Next, next go to your Gemfile and comment out the following 3 lines:

gem 'sass-rails', " ~> 3.1.1"
gem 'coffee-rails', "~> 3.1.1"
gem 'uglifier'

These are all the changes we need to make, but before we can deploy the application, we need to compile the assets, ourselves. This is where you will use the following line.

bundle exec rake assets:precompile

At this point use whatever tool you normally use to deploy your app (in my case, Capistrano). If you’re using Capistrano, don’t forget to commit the new assets that would have just been created in your public/assets folder.

Next you’ll need to log into your cpanel, or whatever actually controls your app, stop and restart it. Even if your deploy tool (like Capistrano) just said it restarted your app, don’t believe it, just restart it. This part caught me for a few hours trying to fix this bug. Even though Capistrano said it restarted the app, it still seemed to hold onto the old gems (sass and coffee) until I actually restarted.

With any luck, try your app now, and if your system is anything like mine, it will have worked.

MacBook Pro unable to connect to internet after waking from sleep

The Problem

I recently I’ve been having some problems with my MacBook Pro.  At first, I would seem to get disconnected from the internet randomly.  After a few weeks, I finally figured out what the pattern was to the problem.

One morning sat down on the couch, opened my MacBook, and as was becoming normal, I was unable to connect to the internet. The AirPort icon on the menu bar was fully black (meaning that the signal was good).

So I went into the browser and tried to to the router address.  To my surprise, I could fully connect to router. I mean fully. I could log in. I could change the settings. I could ping different websites. It all worked flawlessly. But as soon as I went back to my browser and attempted to connect to a website, any browser, it would complain that I wasn’t connected to the internet.

I would turn off the Wi-Fi a few times, and eventually it would connect fully. So then an idea came to me: Maybe it was related to the fact that I just woke it from sleep. I thought back. Every time I could remember, I had just opened the computer, and it would have difficulty connecting.

So I tried it. I made sure I could access different websites. All signs were a go. Then I closed the lid, and waited for the status light to start flashing. After it did, I would wait a few seconds, and then open the lid. I logged in, opened Chrome, and tried gmail. Gmail is currently unavailable it would tell me. So I opened Safari, and tried again. Same story. After going to the AirPort icon turning it off and on a few times, it came back. I decided to try it again. Sure enough same story. So I tried it a few more times.

After having successfully reproduced this exact approach 6 times, I decided it was time to call Apple. I talked to a rep one day, who walked me through a few steps, that failed to get any results, and before we could go through everything, I had to leave for a meeting. I called back a few days later, and got a Wonderful rep. named Ryan. After 17 minutes on the phone, my problem was solved. I was ecstatic.

The Solution

So the solution to the problem was actually pretty simple. I post it here, so that it might help others (or me if the problem recurs sometime). Remember to back up before hand, as it is possible that you might lose something.

I would also recommend storing your Wi-Fi password on your computer (especially if your password is as complex as mine is).

Here’s what worked for me:

  1. Open Finder.
  2. From the Menu at the top, choose ‘Go’ -> ‘Computer’.
  3. Open your hard drive (probably called ‘Macintosh HD’).
  4. Open the ‘Library’ folder.
  5. Open the ‘Preferences’ folder.
  6. Locate the ‘SystemConfiguration’ folder (likely at the bottom).
  7. Drag this folder to your desktop (as far as I can tell, this is to back it up incase something goes wrong)
  8. Once the copy is complete, drag the original to the trash.
  9. In Finder, open Applications (If you don’t have it on the sideback, use ‘Go’ -> ‘Applications’).
  10. Open the ‘Utilities’ folder.
  11. Open ‘Keychain Access’.
  12. Select ‘login’ from the list of Keychains.
  13. In the list to the right, locate an object with the name of your wireless network.
  14. Select it and press ‘delete’ on your keyboard.
  15. Select ‘System’ from the list of Keychains.
  16. Repeat steps 13 and 14 above.
  17. Restart your MacBook.
  18. Once your computer has restarted, connect to your wireless network.

With any luck your computer will now no longer have issues with your wireless network. This worked perfectly with my D-Link DIR-655 router, on which I could reproduce the wireless network issues flawlessly. Since I performed the steps above, my wireless connection has worked flawlessly.