You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.

Problem
You would like to use Carrierwave for file uploads, but you get the following error if you are trying to use factories for running your cucumber scripts:

You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.

That happens if you try to assign inside your factory template, to your file field the path like f.file “path_to_file”

Solution

You would need to slightly modify your factory template to use the file path as follows:

f.file File.open(File.join(Rails.root,"path_to_file"))

ImageMagick, RMagick, Debian installation

Problem
You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first.

Solution
If Imagemagick is not already installed, use the following to install it:
$ sudo apt-get install imagemagick$ sudo apt get install libmagick-dev libmagickwand-dev

You should then be able to install and use the rmagick gem

ImageMagick, RMagick, Mandriva 64 installation

Problem
You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first.

Solution
If Imagemagick is not already installed, use the following to install it:
$ sudo urpmi imagemagick$ sudo urpmi lib64magick-devel

You should then be able to install and use the rmagick gem

Using factory_girl Factory in test console

Problem
You would like to test your factory_girl factories in the rails test console, but you get an error when you try to use an existing factory.

Solution

  1. Start your console in the test evnivornment:
    rails c test
  2. require your factories.rb file in the console:
    require 'absolute_path/to/your/factories.rb'
  3. you should be able to use your factory now :
    t=Factory.create(:existing_factory_name)

mysql2 gem error with bundle install in Rails 3.0.x

Problem
When you try to create a new Rails 3.0.x application, and try to use the ‘mysql2’ gem in your Gemfile without specifying a version you get the following warnings:

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

Solution
Specify the latest version of mysql2 that is compatible with the Rails 3.0.x versions as in:

gem 'mysql2', "~> 0.2.7"

no such file to load — readline (LoadError) in Rails 3.0.7 – Mandriva 2011 64

Problem

When you try to run the console rails c in a new Rails 3.0.7 application, in Mandriva 2011 64bit, and when you use rvm, you get the following error:

no such file to load -- readline (LoadError)

Solution

Similar to an earlier post here, the solution is as follows with the new requirements described

It’s quite like likely that the readline libraries are missing from your installation. To find out which ones go to the directory that the error is indicating (ie):

cd ~/.rvm/src/ruby-1.9..2-head

and then to the following:

cd ext/readline

then run the following:

ruby extconf.rb

If you get something like:
checking for readline/readline.h... no
checking for editline/readline.h... no

then you are probably missing the neccessary header files for readline.
so install them in your system (ie in Mandriva):

sudo urpmi lib64readline-dev,

When the package is installed successfully run the following again:

ruby extconf.rb
make
sudo make install

You should now be able to go back to your project and run rails c with no errors.

uninitialized constant Capybara (NameError) – rails 3.0.7

Problem
When trying to use cucumber in a new rails 3.0.7 application you get the following error when running rake cucumber for the first time:
uninitialized constant Capybara (NameError)

Solution
As cucumber is moving to using capybara instead of webrat as default, if you follow the instructions in the Rspec book for setting up you would get the above error.
What you would need to do is to replace webrat with capybara.
You can do that by commenting out /removing webrat from your Gemfile and then adding the following:

gem 'capybara'
gem 'database_cleaner'

Couldn’t find ‘rspec’ generator – Rails 2.3.10

Problem
You are trying to use rspec with Ruby on Rails 2.3.10, but although you install the rspec and rspec-rails gems you get the following error when you try to run script/generate rspec
Couldn't find 'rspec' generator

Solution
It turns out that there is a problem with the versions used, so by following the instructions for Rails >= 2.3.10 from here, you should be able to install the plugins and use rspec:
ruby script/plugin install git://github.com/dchelimsky/rspec.git -r 'refs/tags/1.3.1'
ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.3.3'
ruby script/generate rspec

where the last tag (1.3.3) should be the latest tag for each gem.

*** NOTE *** If you get an error like :
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map (NoMethodError)

uncomment the following line (line 11) from features/support/env.rb:
require 'cucumber/rails/rspec'
and run rake cucumber again.

Upgrading your Rails 3.0.3 application

Problem
After the announcements in the previous posts about the security vulnerabilities in Rails 3.0.3, you would like to update your application and deploy with the latest 3.0.4 version.

Solution

  • Change your Gemfile to replace
    gem 'rails', '3.0.3'
    with
    gem 'rails', '3.0.4'
  • Run:
    bundle update rails
  • Remove the old gems by using:
    git status
    and then
    git rm name_of_3.0.3_gem
  • Add the new gems to your git
    git add vendor/cache
  • Check in to your repository the new files
    git commit vendor/cache -m 'upgrade to rails 3.0.4'
  • Make sure that you also check in both your Gemfile and Gemfile.lock into your git repository
    git commit Gemfile Gemfile.lock -m 'update Gemfiles to use 3.0.4'
    otherwise when you try to deploy you will see the error:
    You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control
  • push everything to your git repository:
    git push
  • Deploy your application with capistrano as usual:
    cap deploy
  • Your new gems for 3.0.4 should be installed on the share/bundle folder