Persistent Rake DSL method warning - ruby-on-rails

Alright, well I'm trying to fix this problem again. I followed this fix to eliminate the error by reverting to version 0.8.7, which worked the first time. However, now I'm trying to use cucumber and I'm getting it all again.
I tried it again by running gem uninstall rake -v=0.9.2.2 which lists all the gem dependencies. Successfully uninstalled. Then I ran bundle update rake. Using rake (0.8.7). Cool. rake -V. rake, version 0.9.2.2. wat. Same problems return. What am I missing? I thought 9.2 was supposed to fix this bug anyway?

I think this fix is obsolete. Rake 0.9.0 got fixed, and 0.9.2.2 is certainly working. You want to uninstall and completely eradicate rake 0.8.x. Try something like:
gem list -d rake
The -d switch will show the installation directories. If you're using RVM, there may be multiple search paths that get hit, running rvm info will tell you the search path and preference ordering. Depending on the system you're on, your OS may also ship with an old rake version. Try uninstalling everything other than the local gemset (if using RVM) or the latest rake (if not using RVM).

The problem with the rake gem uninstall sounds like you have Rake in your default gemset, check ~/.rvm/gemsets/global.gems It will no doubt have rake in it

Related

rake aborted! ERROR: 'rake/rdoctask' is obsolete and no longer supported

I installed rails 3.2.3 in my pc but for my new project i need to work in rails 3.0.5 so I installed 3.0.5 version of rails and now when i write any rake command i get the following error
rake aborted! ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
currently this rake version is installed in my pc rake (10.1.0)
I know the error says everything but im new in ruby and rails. So i don't understand what to do. I googled it but most of the solutions ask to update rails
I know the error says everything but im new in ruby and rails. So i don't understand what to do. I googled it but most of the solutions ask to update rails
That's unfortunately the best solution. You are using a very old version of Rails that was based on some conventions of the time. Rake has changed and 10.0 is no longer compatible with that Rails version.
You should install a previous rake version. 0.9.0 should be sufficient.
In your Gemfile set
gem 'rake', '0.9.0'
then run $ bundle. Make sure you will prefix every command with
bundle exec
such as
bundle exec rake -T
instead of
rake -T
otherwise the script will fall back again using the most recent version of Rails on your machine.
For your reference, the reason of the error is probably caused by the documentation.rake file that at the very beginning it includes a deprecated rake file, removed in GH-1301.
Keep in mind that, assuming the app will then run, your first goal should be to upgrade your app. In fact, if you try to use it as it is, it's likely you will encounter so many other incompatibilities.
That was fairly simple to debug (assuming you have a reasonable knowledge of Ruby and Rails internals), but others may be harder or even impossible to fix forcing you to nothing else than upgrade.

Rake 10.0.4 not found in sources

I've just pushed a new Rails app from my local development machine to a server I have that has a few Rails apps already on, bundle installs everything correctly and rake tasks run fine, however when I try and start the app it fails with that message.
I've:
Trashed my Gemfile.lock and reran bundle install
Done gem install rake to get the latest version
Checked rake --version shows 10.0.4.
Checked bundle show rake shows 10.0.4
Restarted the server
Now I'm drawing a blank on what it could be. Using Phusion Passenger, rails 3.2.13, ruby 1.9.2p290. I use rvm for managing the environment, but I've not changed anything with it for a long, long while now. The other Rails apps are all working okay without any issues, with similar gem dependencies.
Self fixed, but not sure why. I ran bundle install rake by accident, forgetting it doesn't do what I think and it created a ./rake folder which solved the issue.
Perhaps your application is being run as the wrong user.

How to run a specific version of rake

Background:
I get errors whenever I run rake in an older project. (uninitialized constant Rake::DSL).
The rails project in question is an old project that was started with Rails 2.1 (I think), and since then I've updated the OS on my laptop a couple of times, and made updates along the way to make it run.
Right now, the rails app works fine, provided I have RAILS_GEM_VERSION set to 2.3.5. I'm not sure if the app was completely updated to Rails 2.3.5.
There is no Gemfile in my older project.
If I create a brand-new rails project (and unset RAILS_GEM_VERSION), rake runs fine.
My question: To troubleshoot, I'd like to try newer versions of rake. I'd like to know how to force one specific version to be used, since it appears I have multiple versions installed.
Info on my environment:
$ gem list rake
*** LOCAL GEMS ***
rake (0.9.2.2, 0.9.2, 0.8.7, 0.8.3)
$ rake --version
rake, version 0.8.7
So it looks like it's picking up the 0.8.7 version.
All the help files online seem to tell me to specify the rake version in the Gemfile, but there isn't one in this project. (Maybe it predates gemfiles?)
If I unset the RAILS_GEM_ENVIRONMENT variable altogether, and try to run rake, I get:
rake aborted!
can't activate rails (= 2.3.5, runtime) for [], already activated rails-3.2.8 for []
None of the environment config files in my older project set that variable either.
This may be of help. Have you tried the underscore solution?
Example:
rake _0.9.2_
you can run rake specific version by using this
bundle exec rake ...
more detail see this - bundle exec, rake
You can uninstall the current version of rake and install another desired version using commands similar to the following:
gem uninstall rake 12.3.1
gem install rake 10.5.0
(Note: you might need to run as sudo for permissions)
I had a problem where I received the following error while trying to install rake 10.5.0:
Could not find a valid gem '0.8.7' (>= 0) in any repository
I resolved this problem by adding the following line to my Gemfile:
gem 'rake', ' <11.0'
After editing Gemfile I was able to successfully downgrade rake by updating my gems:
bundle update

Don't Understand Bundler Interaction with Gems

I thought I understood how Bundler works with gems, but after something that recently happened, I am not sure I have it right.
I am developing an Rails application. To start off (and just so I would get familiar with the Rails environment which I haven't worked in before), I did not use an IDE. But, because I'm missing out on some of the advantages of an IDE, I just started using RubyMine. As part of the RubyMine setup, it asked to update all my gems for my existing project.
After that, I could not run "rake [anything]". Every time I did, I received an error of:
You have already activated rake 0.9.3.beta.1, but your Gemfile
requires rake 0.9.2.2. Using bundle exec may solve this.
I was okay updating to the next version of rake - that wasn't a problem - but I don't understand what happened in the first place. What happened that I "activated" a newer version of rake. Ultimately, I ended up solving the problem by putting
gem 'rake', '0.9.3.beta.1'
in my Gemfile and running
bundle update rake
But, I'm still not sure what happened here. If I was using 9.2.2 before, why did it all of a sudden blow up like that and how can I prevent that in the future?
If you are using Rubymine, you should configure it to run rake tasks with bundle exec.
Go to:
Run -> Edit Configurations -> Defaults -> Rake -> Bundler tab and check "Run the script in context of the bundle (bundle exec)"
Delete all tasks already created and the default will apply the next time you create them again. You can also configure individually each task created.
You should really consider installing and using RVM or Rbenv to manage your ruby versions and gemsets. If you go the Rbenv way, the rbenv-gemset plugin can be used to manage gemsets similar to how RVM natively does.
You have already activated rake 0.9.3.beta.1, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this.
At some point between your last bundle execution and installing/configuring/running RubyMine you must have installed rake 0.9.3.beta.1. Because you're not managing your gems through gemsets like RVM or Rbenv will do for you, the default version of Rake became 0.9.3.beta.1 instead of the version installed by bundler, 0.9.2.2.
The above error suggests your Gemfile had something like
gem 'rake', '0.9.2.2'
which does not allow the version of rake being used to be anything but 0.9.2.2.
If you do in fact have 0.9.2.2 on your system in addition to the 0.9.3.beta.1 and your Gemfile is configured for 0.9.2.2, instead of running
rake some:task
you can run
bundle exec rake some:task
and bundler will run some:task through the 0.9.2.2 version of rake. Running tasks related to gems found in a Gemfile through bundleer with bundle exec ... is considered good practice regardless of using RVM or Rbenv.
You can read about bundle exec here.

Crontab + rails3 + bundler

I'm running a crontab that executes a rake task. I'm getting the following error (with MAILTO from crontab):
rake aborted!
no such file to load -- bundler
/Users/Mendel/Sites/misnooit/Rakefile:4
(See full trace by running task with --trace)
I'm using rvm with:
ruby: ruby 1.9.1p378
rails: Rails 3.0.0.beta
$GEM_HOME: /Users/Mendel/.rvm/gems/ruby-1.9.1-p378
bundler: bundler (0.9.11)
The error is pretty self explanatory but I'm not able to fix it.. Is there someone with more knowledge about this matter? Thanks in advance.
I just experienced this. Problem for me was that the instances of rake and ruby I use were built locally, and installed to /usr/local/bin. There are other versions in /usr/bin (must check what I installed using apt-get in the past..).
So, in my crontab file I set the path using
PATH=/usr/local/bin:/usr/bin:/bin
(I was seeing it as PATH=/usr/bin:/bin in the failed crontab emails)
and it works.
Just guessing: is Ruby 1.9.1p378 your default Ruby?
I think it's not so you can just execute rvm --defaults "ruby-1.9.1-p378"
If this doesn't help, are you sure bundler has been installed when ruby 1.9 was used?
Also, in your test/production environment, you may want to run you cron with another user than yourself. So I suggest you install rvm as "root", and set up (still as root) a default RVM that will be the default for all the system users.
And of course, you can override this per user.
I've had good experience using http://github.com/javan/whenever
It uses a Ruby DSL to manage cron tasks and it handles setting all the environment magic.
every 3.hours do
runner "MyModel.some_process"
rake "my:rake:task"
end
have your run the command with --trace asserted to ensure there isn't something obvious in the rake command, but what you could do is chain the crontab commands
rvm 1.9.1;rake do_whatever_task
That way it will load the ruby environment every time prior to running rake.
I had a similar issue this weekend, I found that my Rake Gem was updated to 0.90 you need rake 0.8.7. This solved the issue on my end.

Resources