Heroku can't find SecureRandom - ruby-on-rails

My heroku app is crashing because it can't find the module 'SecureRandom'. I am specifying my Ruby version in the gemfile, and my computer, gemfile and Heroku all seem to match Ruby version numbers, though not the patch numbers.
Other posts have suggested pointing usr/bin/heroku to a specific Ruby file, but I'm not sure how to do that (I have no Heroku bin in my app). This does seem like a Ruby version error. How can I try to fix this?
class OrderItem < ActiveRecord::Base
require 'SecureRandom'
...
end
Heroku log:
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require': No such file to load -- SecureRandom (LoadError)
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
Command line:
/ $ heroku run ruby -v
Running `ruby -v` attached to terminal... up, run.9318
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
/ $ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin12.5.0]
Thanks in advance.

The actual name is securerandom, all lowercase. Linux filesystems are usually case sensitive.
So, change your require to:
require 'securerandom'

Related

Rails 2 “script/plugin” install git://github.com…git throws cannot load such file

I have a rails 2 app and I'm trying to upgrade to Rails 3.1.0 first.
After doing a bit of research, I found this plugin:
https://github.com/rails/rails_upgrade
Which states that the first I have to install a plugin with:
script/plugin install git://github.com/rails/rails_upgrade.git
However, I get this error:
/home/bogdan/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- script/../config/boot (LoadError)
from /home/bogdan/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from script/plugin:2:in `<main>'
My script/plugin file:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
I can run script/server script/console or script/dbconsole with no problem.
What am I doing wrong?
I didn't think that would be the answer but use ruby 1.8.7.
Using an old rails 2 app with ruby 1.9.3 or 2 script/plugin doesn't work, with 1.8.7 script/plugin does for me
I had the exact same problem...ran all over and found the oddest solution
./script/plugin install git://github.com/rails/rails_upgrade.git
and I kept ruby 1.9.3p194 and rails 2.3.14
no 1.8.7 needed

rails console - cannot load custom_require.rb

I have a problem when starting rails console:
Loading development environment (Rails 4.1.1)
cannot load such file -- rubygems/custom_require.rb
Console is running, except that I cannot require any gem. Require in application is okay.
I would like to test in console with any of gems, do you now what is the problem?
Ruby version
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
Thanks.
What version of ruby are you using?
Trying requiring a gem with relative require on the file.
require_relative 'gem_name'

Why Heroku is still not using my Ruby version 1.9.3?

I followed every step in here:
I have this in my gem file
ruby "1.9.3"
and then when I deploy heroku says:
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-1.9.3
-----> Installing dependencies using 1.5.2
Then when I do
heroku run "ruby -v"
I still get
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
Then I added a path:
heroku config:set PATH=bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
Deployed again, and still same result:
I tried:
heroku config:set PATH=bin:vendor/bundle/ruby/1.9.3/bin:/usr/local/bin:/usr/bin:/bin
Still no use:
In my heroku Log I get this:
/app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/definition.rb:390:in `validate_ruby!': Your Ruby version is 1.9.2, but your Gemfile specified 1.9.3 (Bundler::RubyVersionMismatch)
It kind of is driving me nuts, I can't get Heroku to use 1.9.3.
I looked at the following questions as well:
Ruby version is not upgrading on Heroku
Is it possible to run my Rails app on Heroku with Ruby 1.9.3? If so, how?
How can I choose Ruby version on Heroku?
Heroku cedar doesn't upgrade to ruby-1.9.3
Still can't get anywhere
After a very painful search by removing and adding stuff from my most recent commit I realized that a file .bash_profile was added to my Rails Root app that had this in it:
export PGHOST=localhost
export PATH=/usr/local/bin:$PATH
So I just removed that, because this calls up the path to the Ruby version, the default one.
I hope no one ends up making same mistake.

'rake spec' works, 'spec spec' doesn't

When I added my first gem dependency to config/environment.rb, (will_paginate), I'm encountering an error when running rspec as follows:
nik$ spec spec/
Missing these required gems:
will_paginate
You're running:
ruby 1.8.6.369 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.7 at /Users/nik/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
It's not picking up the first ruby binary in my $PATH, which I installed with macports:
nik$ ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin9]
nik$ which ruby
/opt/local/bin/ruby
Curiously, rake spec succeeds:
nik$ rake spec
(in /Users/nik/rails_projects/bigchan)
....................................................................................
Finished in 2.314131 seconds
84 examples, 0 failures
You have different commands looking up different versions of ruby, hence - different sets of gems.
$ which -a ruby
will show you at least two versions of ruby.
ruby 1.8.6.369 probably in /usr/bin (used when running spec spec/)
ruby 1.8.7.299 in /opt/local/bin (used when running rake spec)
Nuke the one you don't need and everything related to it.

Ruby on Rails undefined method `camelize' for "app":String

I just tried to play with Ruby on Rails on Snow Leopard.
I was following this tutorial:
http://developer.apple.com/tools/rubyonrails.html
Whatever I try to do with rails I end up with:
MacBook-Pro-lm:~ lukasz$ rails blog
**undefined method `camelize' for "app":String**
MacBook-Pro-lm:~ lukasz$ rails --help
**undefined method `camelize' for "app":String**
Really basic things... however - verbosing rails works:
MacBook-Pro-lm:bin lukasz$ rails -v
Rails 2.3.5
MacBook-Pro-lm:~ lukasz$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]
MacBook-Pro-lm:bin lukasz$ gem -v
1.3.7
So it seems I have installed and upgarded ruby (using macports), rubygems and rails successfully (according to terminal). There are also few other packages installed to support we development like passenger and mysql5, etc...
I can find ruby installed in the
/opt/local/bin directory. My environment PATH variable is:
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
The is something fishy going on. It must be some stupid basic problem. Google says that there could be a problem with ruby-iconv library but I can not find/install this package using port or gem commands.
Plese help.... what am I missing here?
You might want to try to check where the gem was installed:
gem list -d rails
Compare the gem installation directory with other gems that rails needs. It seems to me that it is a ruby gems issue. Make sure all the gems was installed with macports version of rubygems. It is not possible to mix and match.
Hopefully it helps.

Resources