Tag Archives: ubuntu

Simple Staging/Test Environment with Heroku – Ruby on Rails

Hey everyone,

This is just a quick guide on how to create a test/staging environment with Heroku.

-- Create staging environment
heroku create --remote staging
 
-- Push to staging app
heroku push staging master
 
-- Run rake db:migrate on staging app
heroku run rake db:migrate --remote staging
 
-- Add pgbackups add ons
heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote heroku
 
-- Create backup of production data
heroku pgbackups:capture --remote heroku
 
-- Copy to staging environemnt
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote heroku` --remote staging
 
-- Create a new config file called staging.rb (/config/environments/staging.rb)
 
-- Add environment variables
heroku config:add RACK_EVN=staging RAILS_ENV=staging --remote staging
 
-- Ready to go !

For those of you using git branches etc, the following may come in handy as well:

-- Create local development branch
git branch development
 
-- Switch to dev branch
git checkout development
 
-- Make your changes and commit them
git init
git add .
git commit -m "My changes"
 
-- Push to staging environment (local development branch to staging environment master branch)
git push staging development:master

If you run into any trouble, I found the following links pretty helpful:

http://stackoverflow.com/a/6931462/522859
https://devcenter.heroku.com/articles/pgbackups#transfer
https://devcenter.heroku.com/articles/multiple-environments

Let me know if you’ve got anything to add.

Assets:Precompile (Rake Aborted) – Heroku

Hey everyone,

I ran into the following error over the weekend while trying to push to heroku:

Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host “127.0.0.1” and accepting
TCP/IP connections on port 5432?

This stackoverflow post helped to solve the issue. All you need to do is add the following line to your application.rb file:

1
2
#Applicication.rb
config.assets.initialize_on_precompile = false

Let me know if you have any problems.

Installing SQL Developer on Ubuntu – make-sqldeveloper-package chmod: missing operand after `755′

Hey everyone,

I was following a guide while trying to install SQL Developer on Ubuntu, however I ran into the following error:

make-sqldeveloper-package chmod: missing operand after `755′

 

To fix it, simply change line number #381 in ‘/usr/bin /make-sqldeveloper-package’ as follows:

Original

${FIND} "${OPTDIR}" ! \( -type d -o -name "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "shell script text executable" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS}

Modified

${FIND} "${OPTDIR}" ! \( -type d -o -name "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "shell script" | ${GREP} ${GREP_OPTS} "text executable" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS}

Thanks to this blog post for the solution, just note that it is Polish.

Let me know if you have any issues!

WARN Could not determine content-length of response body – Ruby on Rails

Hey everyone

I was going through my development logs today and noticed that the following line was appearing everywhere:

WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

While nothing appeared to be wrong, it made the logs a lot harder to read. A stackoverflow post indicates that this is a webrick issue that can be avoided by switching to thin. This is also the recommended option for heroku. In order to use thin, you simply need to add it to your Gemfile:

1
2
3
4
5
#Gemfile
 
#Added gems
gem 'therubyracer' #JavaScript
gem 'thin' #Instead of webrick

Run bundle install

chris@chris-VirtualBox:~/calendar$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.2) 
Using i18n (0.6.1) 
Using multi_json (1.4.0) 
Using activesupport (3.2.9) 
Using builder (3.0.4) 
Using activemodel (3.2.9) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.2) 
Using actionpack (3.2.9) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.9) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.9) 
Using activeresource (3.2.9) 
Using bcrypt-ruby (3.0.1) 
Using bundler (1.2.3) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.9) 
Using coffee-rails (3.2.2) 
Installing daemons (1.1.9) 
Installing eventmachine (1.0.0) with native extensions 
Using jquery-rails (2.1.4) 
Using libv8 (3.3.10.4) 
Using pg (0.14.1) 
Using rails (3.2.9) 
Using sass (3.2.3) 
Using sass-rails (3.2.5) 
Using therubyracer (0.10.2) 
Installing thin (1.5.0) with native extensions 
Using uglifier (1.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

And finally start thin:

chris@chris-VirtualBox:~/calendar$ rails s thin
=> Booting Thin
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

If you’d prefer to keep using Webrick, the following patch is said to resolve the issue:
https://bugs.ruby-lang.org/attachments/2300/204_304_keep_alive.patch

Link

Hey everyone,

I’ve just done a fresh install of RVM using the guide below. There were a few dependencies missing, but other than that it all went pretty smoothly.

Link: http://stjhimy.com/posts/10-five-quick-steps-to-set-up-rvm-with-rails-2-and-rails3

Next time I do an install I’ll try to document the whole thing, but for now that link is probably one of the better/simpler guides I’ve come across. If you have any problems please leave a comment below and I’ll try to get back to you.

UPDATE:

Just another guide I’ve come across that seems to work well, this one is a complete “start to finish” one:
http://rails.vandenabeele.com/blog/2011/11/26/installing-ruby-and-rails-with-rvm-on-ubuntu-11-dot-10/

Heroku Timezones – Ruby on Rails

Hey everyone,

Just a quick post on how to adjust the timezone on Heroku, comes in handy when using the log files.

#Console
$ heroku config:add TZ=Australia/Brisbane

There is a fairly detailed StackOverflow post at the following link if anyone is interested in more info:
http://stackoverflow.com/questions/2719330/why-does-heroku-log-using-the-server-time-rather-than-the-rails-time-zone

The language options can also be found on the following wikipedia page:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Cannot Generate Tempfile – Ruby on Rails

Ran into the following problem, still not too sure what caused it but this seems to have fixed it:

Error

cannot generate tempfile `/home/chris/cartsite/tmp/cache/assets/sprockets%2Fd585a06e2ee6203ccb04c8b84150d14d20120804-8682-7q77nb-9'

Just run the following:

$ rake tmp:clear

Let me know if you come across the cause, I’d be interested to know.

Browse Folders as Root – Ubuntu

Just a quick post on how to browse folders as root in Ubuntu. Simply enter the following:

chris@chris-VirtualBox:/etc$ sudo nautilus

Once you’re in there you can view hidden files by pressing Ctrl+H.

If, like me, you’re coming from a Windows background – this may make things a little easier. Leave a comment below if you have any more useful tips!

sqlite3.h is missing – Ruby on Rails

Just an error I ran into while running bundle install on a new ubuntu virtual:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
 
/usr/bin/ruby1.8 extconf.rb 
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
 
Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/ruby1.8
	--with-sqlite3-dir
	--without-sqlite3-dir
	--with-sqlite3-include
	--without-sqlite3-include=${sqlite3-dir}/include
	--with-sqlite3-lib
	--without-sqlite3-lib=${sqlite3-dir}/lib
	--enable-local
	--disable-local

To fix it, simply run the following:

sudo apt-get install libsqlite3-dev

Could not find a JavaScript Runtime – Ruby on Rails

Ran into the following issue today starting a new app on a virtual Ubuntu box:

Could not find a JavaScript runtime

Thankfully there’s a quick fix, simply install nodejs:

 
chris@chris-VirtualBox:~/Desktop$ sudo apt-get install nodejs
 
 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  postgresql-client-8.4 postgresql-8.4
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libc-ares2 libev4 libv8-3.1.8.22
The following NEW packages will be installed:
  libc-ares2 libev4 libv8-3.1.8.22 nodejs
0 upgraded, 4 newly installed, 0 to remove and 77 not upgraded.
Need to get 1,938 kB of archives.
After this operation, 6,066 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://au.archive.ubuntu.com/ubuntu/ oneiric/universe libv8-3.1.8.22 i386 3.1.8.22-1ubuntu2 [1,386 kB]
Get:2 http://au.archive.ubuntu.com/ubuntu/ oneiric/main libc-ares2 i386 1.7.4-1 [37.3 kB]        
Get:3 http://au.archive.ubuntu.com/ubuntu/ oneiric/universe libev4 i386 1:4.04-1 [29.5 kB]       
Get:4 http://au.archive.ubuntu.com/ubuntu/ oneiric/universe nodejs i386 0.4.9-1ubuntu3 [486 kB]  
Fetched 1,938 kB in 18s (106 kB/s)                                                               
Selecting previously deselected package libv8-3.1.8.22.
(Reading database ... 158699 files and directories currently installed.)
Unpacking libv8-3.1.8.22 (from .../libv8-3.1.8.22_3.1.8.22-1ubuntu2_i386.deb) ...
Selecting previously deselected package libc-ares2.
Unpacking libc-ares2 (from .../libc-ares2_1.7.4-1_i386.deb) ...
Selecting previously deselected package libev4.
Unpacking libev4 (from .../libev4_1%3a4.04-1_i386.deb) ...
Selecting previously deselected package nodejs.
Unpacking nodejs (from .../nodejs_0.4.9-1ubuntu3_i386.deb) ...
Processing triggers for doc-base ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Processing triggers for man-db ...
Setting up libv8-3.1.8.22 (3.1.8.22-1ubuntu2) ...
Setting up libc-ares2 (1.7.4-1) ...
Setting up libev4 (1:4.04-1) ...
Setting up nodejs (0.4.9-1ubuntu3) ...
update-alternatives: using /usr/bin/node to provide /usr/bin/js (js) in auto mode.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
chris@chris-VirtualBox:~/Desktop$

Let me know if you have any issues.