Category Archives: Ruby

rails console hangs

“rails c” hangs with no error messages and no response.

solution: stop spring using the following command
“spring stop” or “bin/spring stop”

spring will automatically start back up when you run the rails c command.

How to Convert HTML to a PDF File in Ruby 2.0 on Ubuntu 12.04 LTS

You could test this in IRB:

 

Install RVM and HomeBrew for Yosemite (Mac OSX v10.10)

Download “Command Line Tools (OS X 10.10)” for Xcode 6.1.1 from https://developer.apple.com/downloads/index.action

Screen Shot 2014-12-03 at 9.57.54 AM

I installed rvm for multi-user.

\curl -sSL https://get.rvm.io | sudo bash -s stable

This will automatically download and install homebrew for you.

Make sure the user who is installing this, has added “rvm” to their groups. You can do this under “System Preferences” –> “Users & Groups”. Go to rvm group, and check off the usernames you would like to add the group to. (make sure the lock the botton is unlocked).

Screen Shot 2014-12-03 at 10.03.04 AM Screen Shot 2014-12-03 at 10.03.16 AM Screen Shot 2014-12-03 at 10.03.40 AM

Installing ruby version 2.1.5

rvm install 2.1.5

RVM will automatically grab all the dependencies, packages, and updates via homebrew.

Installing Ruby 2.0.0 with RVM, Homebrew, and Mac OSX Mountain Lion

I had a lot of trouble installing ruby 2.0.0 on mountain lion.  Tried various things recommended on different forums and blogs, but the one that was easiest and worked best for me was the one written by Christopher Kaukis on the Interworks blog.  In short, the steps are as follows.

1.  Install the latest version of Xcode from the App Store.  (at this time of writing it is version 4.6)

2.  Go to xcode’s preferences and install the Command Line Tools

3.  Install Homebrew.

4.  Check requirements for RVM and install it.  (I use the multi-user install)

  • brew tap homebrew/dupes
  • brew tap –repair homebrew/dupes
  • brew install autoconf automake libtool pkg-config apple-gcc42 libyaml readline libxml2 libxslt libksba openssl sqlite
  • curl -L https://get.rvm.io | sudo bash -s stable

5.  Upgrade RVM to the latest repository source version and install ruby 2.0.0 then start using it.

  • rvm get head
  • rvm install 2.0.0
  • rvm use 2.0.0

 

 

 

Can’t install RMagick 2.13.1. Can’t find Magick-config for mac

brew install imagemagick

mdfind MagickWand.h

C_INCLUDE_PATH=/path/MagickWand.h gem install rmagick

Example:
C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick/wand/MagickWand.h gem install rmagick

Might have to take these additional steps if you are using mountain lion.

http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion

It appears it’s a problem reported on the Homebrew github repo (https://github.com/mxcl/homebrew/issues/16625) blaming rmagick itself not supporting newer versions of imagemagick. On that same issue (https://github.com/mxcl/homebrew/issues/16625#issuecomment-11519383), you can find this link: https://coderwall.com/p/wnomjg which actually worked for me. This is what he does:

cd /usr/local/Cellar/imagemagick/6.8.0-10/lib
ln -s libMagick++-Q16.7.dylib libMagick++.dylib
ln -s libMagickCore-Q16.7.dylib libMagickCore.dylib
ln -s libMagickWand-Q16.7.dylib libMagickWand.dylib

upgrade ruby in rvm without losing gems

How can I upgrade the ruby interpreter without losing my gems inside my gemsets?

Use rvm upgrade

Say I want to upgrade from ruby 1.9.3 to ruby 1.9.3-p286 from within rvm and not loose my gemset environments.  I would type the following command.

rvm upgrade 1.9.3 1.9.3-p286

Then you just follow the command line prompts that come up, simple as that. =D

index name too long in rails 3.2 and mysql 5.5

If you get an error that says the auto-generated index name is too long (limited to 64 characters) during a rails migration, add a name to it in the last argument to overwrite the generated name with your custom shorter name.

Sample Error Message:

== AddColumnNameToPrices: reverting ============================================
— remove_column(:prices, :column_name)
rake aborted!
An error has occurred, this and all later migrations canceled:

Index name ‘temp_index_altered_prices_on_column_and_other_column_and_third_column’ on table ‘altered_prices’ is too long; the limit is 64 characters

Solution:
add_index :designations, [ :scope_type, :scope_id, :role_id, :user_id ], :unique => true, :name => ‘my_index’