Problems with Rake after switching to rvm and rails 3 - ruby-on-rails

So the crux of the problem, is I get the following error when running
rake -T
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method SeenicServer::Application#task called at /home/grantismo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
rake aborted!
no such file to load -- parse_tree
So obviously I did, gem install ParseTree.
Running gem list -d ParseTree produces:
*** LOCAL GEMS ***
ParseTree (3.0.7)
Author: Ryan Davis
Rubyforge: http://rubyforge.org/projects/parsetree
Homepage: http://rubyforge.org/projects/parsetree/
Installed at: /home/grantismo/.rvm/gems/ruby-1.9.2-p180
ParseTree is a C extension (using RubyInline) that extracts the
parse tree for an entire class or a specific method and returns it
as a s-expression (aka sexp) using ruby's arrays, strings, symbols,
and integers
it looks like I'm using the correct rake
which rake
/home/grantismo/.rvm/gems/ruby-1.9.2-p180/bin/rake
Most of the explanations I've read say to run sudo gem install ParseTree, but I don't understand why I should be installing with sudo if I'm managing gems through rvm.
Any ideas? I'm a unix noob, so it might be something simple. Thanks for your time.

You need to make sure your Gemfile has a gem 'ParseTree' line in it, otherwise Rails won't load it (even if the system has it installed).
After adding the line, do a bundle install.

Related

Rails: TypeError: NullDecompressor is not a class

When I try execute bundle exec puma -e production -b tcp://127.0.0.1:3000 or bundle exec rspec spec/ i get message:
/home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/zip-2.0.2/lib/zip/zip.rb:274:in : NullDecompressor is not a class (TypeError)
I have Rails 4.1.14.1 and Ruby 2.1.4
You probably need to use an older version of the rubyzip gem. In 2013, more precisely in this commit, the NullDecompressor has been rewritten from a class to a module. Now, some of your other code expects it to be a class but finds a module, that's why you get the TypeError.
So it seems that using the rubyzip-1.0.0 version might fix your issue.
BTW, your error points to zip-2.0.2 which seems to be an even older gem that have been later converted to the rubyzip-1.0.0 gem.

"Could not find generator figaro:install"

I'm using the "Learn Ruby On Rails" pdf book from learn-rails.com.
I'm at chapter 13, "Configure". Where we are supposed to do the command: "rails generate figaro:install"
In chapter 12 we installed the figaro gem,: "We’ve already installed the figaro gem in the Gemfile and run bundle install."
When I run that command I get: "Could not find generator figaro:install."
I started searching for similar questions, and I did find this question here: rails generate - "Could not find generator"
where they were recommended to include "migration" into the command as well.
I included it in my command and I got it to do something, but I don't think it's doing what it should be?
invoke active_record
/Users/NormalUse/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activerecord-4.0.2/lib/rails/generators/active_record/migration/migration_generator.rb:57:in `validate_file_name!': Illegal name for migration file: figaro:install (ActiveRecord::IllegalMigrationNameError)
(only lower case letters, numbers, and '_' allowed)
from /Users/NormalUse/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activerecord-4.0.2/lib/rails/generators/active_record/migration/migration_generator.rb:10:in `create_migration_file'
Then about 20 more lines as well. I just didn't want to put it all here.
The author goes on to say:
"Using the rails generate command, the figaro gem generates a config/application.yml file and lists it in your .gitignore file. The .gitignore file prevents the config/application.yml file from being saved in the Git repository so your credentials are kept private."
When I go to my project directory, and look inside the "config" folder, I do have an "application" file, but it ends with ".rb" and not "yml". So obviously the command didn't do what it is supposed to do, right?
Does anyone have any ideas for me?
I'm using Ruby 2.0.0 and Rails 4.0.2 with RVM on Mac OSX 10.7.5
If you do this tutorial nowadays instead of "rails generate figaro:install" run command "figaro:install" due to figaro 1.0.0 version https://github.com/laserlemon/figaro
As you're learning (welcome to the Rails community btw!), let me explain what Figaro does & how to use (install) it:
Figaro
Figaro is a way to create ENV variables in both development & production. It's a gem which you have to install before invoking from the Rails cmd
Like other Ruby gems in Rails, you have to add it to your Gemfile, which lists all the plugins your app will use. According to RubyGems.org, you could list it in your Gemfile like this:
#Gemfile
gem "figaro", "~> 0.7.0"
After you've added this line to your Gemfile, you need to install it. To do this, you should run bundle install to run the bundler (installer)
Once you've done this, you need to run this command from cmd:
rails generate figaro:install
Error
Your errors seem to indicate you've got migration problems?
Illegal name for migration file: figaro:install
(ActiveRecord::IllegalMigrationNameError)
I would guess you called this command:
rake db:migrate figaro:install
If this is the case, you should perform any migrations by running rake db:migrate and then rails generate figaro:install. This will run the commands separately, which should help them work
Please try below one:
bundle exec figaro install
Thank you

Rails: gem.config & rake gems:install -- no such file to load

I'm trying to use config/environment.rb to install a ruby gem dependency (because I don't have sudo access to our server; ergo, can't just call gem install hpricot).
I've tried including sundry arguments (:version, :source, :lib) but I still get rake aborted! no such file to load -- hpricot
Update: It turns out that when I remove the plugin which requires hpricot, then I can execute rake gems:install successfully. But that's not very helpful. It means that if I ever move my app, I run into a problem of being unable to rake its gems (because I will have reinstalled the plugin and added features that depend on it).
How is this supposed to work?
Sys: WinXP, Ruby 1.8.7, Rails 2.3.5
Rails is trying to load the gem before executing the rake task. This is a known issue with rails 2.x. The only solution I know of is to switch to using bundler to manage gems or manage then manually.
Bundler can be used with rails 2 but it requires some modifications to your application and deployment scripts. This is a good place to start: http://gembundler.com/rails23.html
rake gems:install has been deprecated because it never really worked. You can imagine having a gem installer with dependencies to the very gems it's trying to install is a bad idea.
It's advisable to use bundler instead if that's an option.
Bundler allows you to install gems to any destination you want, something specifically intended to side-step the whole "requires sudo" problem you describe. It's often as easy as this:
bundle install --path ~/my_gems/
You can make your Rails 2.3.x application use Bundler by following a few simple steps and from there your life will be a lot easier.

What does bundle exec rake mean?

What does bundle exec rake db:migrate mean? Or just bundle exec rake <command> in general?
I understand that bundle takes care of maintaining things in the Gemfile. I know what the word "exec" means. I understand that rake maintains all the different scripty things you can do, and I know that db:migrate is one of those. I just don't know what all these words are doing together. Why should bundle be used to execute rake to execute a database migrate?
bundle exec is a Bundler command to execute a script in the context of the current bundle (the one from your directory's Gemfile). rake db:migrate is the script where db is the namespace and migrate is the task name defined.
So bundle exec rake db:migrate executes the rake script with the command db:migrate in the context of the current bundle.
As to the "why?" I'll quote from the bundler page:
In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.
However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
You're running bundle exec on a program. The program's creators wrote it when certain versions of gems were available. The program Gemfile specifies the versions of the gems the creators decided to use. That is, the script was made to run correctly against these gem versions.
Your system-wide Gemfile may differ from this Gemfile. You may have newer or older gems with which this script doesn't play nice. This difference in versions can give you weird errors.
bundle exec helps you avoid these errors. It executes the script using the gems specified in the script's Gemfile rather than the systemwide Gemfile. It executes the certain gem versions with the magic of shell aliases.
See more on the man page.
Here's an example Gemfile:
source 'http://rubygems.org'
gem 'rails', '2.8.3'
Here, bundle exec would execute the script using rails version 2.8.3 and not some other version you may have installed system-wide.
This comes up a lot when your gemfile.lock has different versions of the gems installed on your machine. You may get a warning after running rake (or rspec or others) such as:
You have already activated rake 10.3.1, but your Gemfile requires rake 10.1.0. Prepending "bundle exec" to your command may solve this.
Prepending bundle exec tells the bundler to execute this command regardless of the version differential. There isn't always an issue, however, you might run into problems.
Fortunately, there is a gem that solves this: rubygems-bundler.
$ gem install rubygems-bundler
$ $ gem regenerate_binstubs
Then try your rake, rspec, or whatever again.
It should probably be mentioned, that there are ways to omit bundle exec (they are all stated in chapter 3.6.1 of Michael Hartls Ruby on Rails Tutorial book).
The simplest is to just use a sufficiently up-to-date version of RVM (>= 1.11.x).
If you're restricted to an earlier version of RVM, you can always use this method also mentioned by calasyr:
$ rvm get head && rvm reload
$ chmod +x $rvm_path/hooks/after_cd_bundler
$ bundle install --binstubs=./bundler_stubs
The bundler_stubs directory should then also be added to the .gitignore file.
A third option is to use the rubygems-bundler gem if you're not using RVM:
$ gem install rubygems-bundler
$ gem regenerate_binstubs
When you directly run the rake task or execute any binary file of a gem, there is no guarantee that the command will behave as expected. Because it might happen that you already have the same gem installed on your system which have a version say 1.0 but in your project you have higher version say 2.0. In this case you can not predict which one will be used.
To enforce the desired gem version you take the help of bundle exec command which would execute the binary in context of current bundle. That means when you use bundle exec, bundler checks the gem version configured for the current project and use that to perform the task.
I have also written a post about it which also shows how we can avoid using it using bin stubs.
I have not used bundle exec much, but am setting it up now.
I have had instances where the wrong rake was used and much time wasted tracking down the problem. This helps you avoid that.
Here's how to set up RVM so you can use bundle exec by default within a specific project directory:
https://thoughtbot.com/blog/use-bundlers-binstubs
It means use rake that bundler is aware of and is part of your Gemfile over any rake that bundler is not aware of and run the db:migrate task.

Configuring and running Ruby-On-Rails migrations

I'm (completely) new to ROR and have got an application to maintain and upgrade. I've the source code and am trying to build database using db:migrate rake command. I've started using Aptana Studio for the development. When I run dg:migrate I get following errors:
rake db:migrate
(in G:/Projects/.../.../trunk)
MissingSourceFile no such file to load -- rcov/rcovtask
WARNING: rcov tests won't work
Looking for release_type overrides ...
=> Loading G:/Projects/.../.../trunk/config/release_type_config.rb
DEPRECATION WARNING: ActiveRecord::Base.allow_concurrency=has been deprecated and
no longer has any effect. Please remove all references to allow_concurrency=..
(called from allow_concurrency= at D:/Ruby/lib/ruby/gems/1.8/gems/
activerecord-2.3.5/lib/active_record/connection_adapters/abstract/
connection_specification.rb:98)
DEPRECATION WARNING: ActiveRecord::Base.verification_timeout= has been deprecated
and no longer has any effect. Please remove all references to
verification_timeout=.. (called from verification_timeout= at
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/
connection_adapters/abstract/connection_specification.rb:108)
rake aborted!
no such file to load -- hpricot
I've installed hpricot gem also (version 0.8).
What is the remedy for this?
Install the rcov gem:
gem install relevance-rcov --source http://gems.github.com
The most significand error is
rake aborted!
no such file to load -- hpricot
You need hpricot. You can install it running the following command on the command line
gem install hpricot
Maybe your system can't find the gems. This could be a path problem, see this post for details.

Resources