Mint12 : Heroku Toolbelt – `require’: cannot load such file

If you are running Linux Mint 12 as your Ruby / Rails development environment and you are planning on deploying to Heroku you will need to install Heroku’s Toolbelt in order to execute the commands necessary to create an application in their cloud as well as various other administrative commands.

Heroku provides detailed tutorials to assist you in setting up your environment but as expected they are pretty agnostic when it comes to specific Linux distributions.

For Linux Mint 12 doing the GEM install of the Toolbelt you run the following command and it executes without issue:

gem install heroku foreman

But when you attempt the login command you may get the following error:

heroku login
/rubygems/custom_require.rb:55:in `require': cannot load such file -- readline (LoadError)

I found this was due to a missing gem which is required by either the Heroku Toolbelt or Foreman gems. To correct this issue I installed the ruby readline gem with the following command:

gem install rb-readline

Once the install completed I attempted the Heroku login command again and it was successful.

Rails3: ActiveRecord accepts_nested_attributes_for not working (can’tmass-assign protected attributes)

In one of my applications I ran into a situation where I needed to have a single form handle a model as well as several of its associations. Meaning I needed the form to handle CRUD events for the model plus the associated models auto-magically. With that objective I remembered a RailsCast.com video cast explaining how to use the ActiveRecord ‘accepts_nested_attributes_for’ method.

So I jumped on the web and coded along while I watched the cast. But for some strange reason the code from the cast just wouldn’t work. When I saved the survey no associated questions were saved to the database despite the fact that the survey came back as successfully saved. So I triple checked that I had it all correct. Once I was satisfied that it was correct I started digging deeper when I noticed in the passenger logs in my console the following error message hidden nicely within the POST printout and the SQL statements.

<<<>>>

WARNING: Can’t mass-assign protected attributes: questions_attributes

<<<>>>

That made me think, Rails has started doing a much better job protecting our applications from Mass-Assignment attacks by requiring us to explicitly set the model attributes which are accessible and can be directly updated via a form post. I then reviewed the POST parameters to see what was being returned by the form (see below).

<<<>>>

Parameters: {“utf8″=>”✓”, “authenticity_token”=>”8XugXn/UwE+m4m2BR2pfTy7oVfUI+jKnPYaSNwKiD1s=”, “survey”=>{“name”=>”test”, “questions_attributes”=>{“0″=>{“content”=>”question1”}, “1”=>{“content”=>”question2”}, “2”=>{“content”=>”question3”}}}, “commit”=>”Submit”}

<<<>>>

Within the parameter list for the survey sent back by the form I noticed the addition of the ‘questions_attributes’ hash which holds each question with its associated hash of fields and values. Being that the ‘questions_attribute’ is a newly introduced attribute to a survey via the ‘accepts_nested_attributes_for’ method it now becomes filtered by Rails as NOT mass-assignable.

Once I added ‘questions_attributes’ to the survey model’s ‘attr_accessible’ method and retested it worked without an issue. Hope this helps those who might be stuck trying to get nested forms to work.

Ruby: Mint12 Sqlite3 Install Issues (sqlite3.h)

On the latest version of Linux Mint 12 (the Linux platform I prefer for Ruby development) I ran a bundle install on a small application using Sqlite3 and ran into the following error message. After a little Google search I found that my installing Sqlite3 did not give Gem all the build files it requires to build the Sqlite3-ruby gem with native extensions. So if you are running into the same issue make sure you run the following commands prior to running bundle install.

<<<>>>

sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev

<<<>>>

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/home/tim/.rvm/rubies/ruby-1.9.2-p290/bin/ruby 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
–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=/home/tim/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
–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
Gem files will remain installed in /home/tim/.rvm/gems/ruby-1.9.2-p290@CorDev1.9.2/gems/sqlite3-1.3.6 for inspection.
Results logged to /home/tim/.rvm/gems/ruby-1.9.2-p290@CorDev1.9.2/gems/sqlite3-1.3.6/ext/sqlite3/gem_make.out