undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError) - ruby-on-rails-3

I am working on rails, suddenly rails server stops working. It's working fine and I have used following command [platform windows 7]
gem install -v=2.3.5 rails
And when I use rails s, it's giving the following error:
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator/options.rb:32:in `default_options': undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError)
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator/base.rb:90:in `<class:Base>'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator/base.rb:85:in `<module:Generator>'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator/base.rb:48:in `<module:Rails>'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator/base.rb:6:in `<top (required)>'
from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails_generator.rb:34:in `<top (required)>'
from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.5/bin/rails:14:in `<top (required)>'
from c:/Ruby193/bin/rails:23:in `load'
from c:/Ruby193/bin/rails:23:in `<main>'
$ rails -v
Rails 2.3.5
$ ruby -v
ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

I had the same problem, but it was the result of having the gem rmagick.
I ran the following:
gem uninstall rmagick
gem cleanup
And then re-ran bundle in my stack and it worked for me again.

I have solved this issue. Use following command and problem gone
gem install rails
This will install updated rails and all thing working find again.

Running bundle exec rails s worked for me.
My project was using Rails 3.x but when I ran rails -v I got 2.3.17 which is the version used by a project I worked on just before. Somehow installing this version must have be set as "default".
Could someone explain this ?

if you are using latest version of rails 3 or rails 4 then use class_attributes instead of write_inheritable_attribute, i.e.
class_attribute :variable_name
self.variable_name = value
instead of
write_inheritable_attribute(:variable_name, value)

I had this issue, and it happens that I was in using the wrong ruby and gemset in rvm.

(#jeremy-f and #alex-villa are on the right track to identifying the problem itself.)
The problem here is that the rails ... command in Rails version 2 is a generator, equivalent to rails new ... in Rails 3+. So rails s is a Rails 2 command to generate a new Rails 2 app called "s" (whereas most of us when we write rails s intend the Rails 3 usage, i.e. start a server!)
If you install a gem, it will usually install its binary in the path, so you should be able to cause this error by doing gem install rails -v 2.3.15 then rails s as the OP says.
Three ways to fix it:
gem install rails to install a newer version of Rails (you may have to specify a version >= 3.0)
Run the app with bundle exec rails s (only if you have Rails 3 in your Gemfile)
The usual way to run a Rails 2 project is simply script/server

Related

How to solve rake db:migrate error in RoR?

I am using the gem version 2.0.7 and rails version 3.0.7.
While i am running the rake db:migrate command it's throw the following error.
$ rake db:migrate --trace
rake aborted!
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (ava
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/rdoctask.rb:2:in `<top
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `loa
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `blo
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:
c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:i
C:/Users/m/Documents/Aptana Studio 3 Workspace/rail1/Rakefile:6:in `<top (requir
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `l
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `l
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:637:in `
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:94:in `b
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:93:in `l
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:77:in `b
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `r
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>
c:/Ruby193/bin/rake:23:in `load'
c:/Ruby193/bin/rake:23:in `<main>'
How to solve it.
Please hlep me. Thanks in advance
The key part of the error message is this:
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (ava
If you search for the error message on StackOverflow or Google you will find at least three different questions on the same topic, among others this:
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead
The highest voted answer at the time of writing suggests editing your Rakefile from:
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
to:
require 'rake'
require 'rake/testtask'
require 'rdoc/task'
require 'tasks/rails'
If I were you, I would try to upgrade Rails to 3.2 and see if the problem persists. If that is not an option the older questions will hopefully be of help.
it can be solved it by installing an older version of rake, and uninstalling current 10.1.0 version:
gem install rake --version 0.8.7
gem uninstall rake --version 10.1.0

rails -v shows wrong version when using rvm

I've just tried to update to Rails 3.1.3 using RVM with the following commands:
rvm install ruby-1.9.3-p0
rvm --default use ruby-1.9.3-p0
If I query the current version or ruby:
ruby -v
I get the correct version: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
Then to update the gems:
gem update --system
This gives me version 1.8.24
I then create my gemset and set it as my default:
rvm ruby-1.9.3-p0#rails313 --create --default
and finally install the Rails gem:
gem install rails
When I query the version of rails:
rails -v
I get Rails 3.0.11 ... my old version of Rails
If I try to start my Rails server
rails s
I get a huge error:
.rvm/gems/ruby-1.9.3-p0#rails313/gems/activesupport-3.0.11/lib/active_support dependencies.rb:239:in `require': dlopen(/Users/lss_dev/.rvm/gems/ruby-1.9.3-p0#rails313/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.bundle, 9): Symbol not found: _ruby_current_thread (LoadError)
With a lot of complaints about dependencies.
My gemfile.lock does contain the following block:
rails (3.0.11)
actionmailer (= 3.0.11)
actionpack (= 3.0.11)
activerecord (= 3.0.11)
activeresource (= 3.0.11)
activesupport (= 3.0.11)
bundler (~> 1.0)
railties (= 3.0.11)
Does this have something to do with it or should I even be touching the gemfile.lock file??
I'm using rvm version 1.10.0, any help would be appreciated
To answer my own (extended) question...
Trashing the gemfile.lock file allowed me to just run
bundle install
ensuring that I had my Rails gem set to the correct version (3.1.3), which worked. The issue that I was running into then was when I started my rails server I got the following browser error
undefined method `consider_all_requests_local' for ActionController::Base:Class
Initially I thought this was due to some routing changes in Rails 3.1.* As it turned out in my application_controller.rb file I was dealing with 404 errors and had the following block:
unless ActionController::Base.consider_all_requests_local
rescue_from Exception, :with => :render_404
end
ActionController::Base.consider_all_requests_local
Is now deprecated and substituting in:
Rails.application.config.consider_all_requests_local
Did the trick.
Thank you for your help and I hope this helps someone in the future
You may have to swap the version of rvm / ruby and then install.
This may be of use: https://rvm.io/gemsets/basics/

rails and gem commands give error

when I run any rails specific command in the console it gives me an error. For instance, i tried
rails -v then it gives me error
/usr/local/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb:194:in `each': rehash occurred during iteration (RuntimeError)
from /usr/local/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb:194:in `<module:RbConfig>'
from /usr/local/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb:5:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:31:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/bin/rails:9:in `<main>'
The same happens for gem commands. Ruby is working fine.
Please Help. Thanks in Advance.
Not sure if that is the problem but according to the rails website, they only support ruby 1.8.7 or 1.9.2 .
and it seems you got 1.9.1.
The error message is showing that when you run rails, it is using 1.9.1. Per Wissam's comment, not sure if the ruby version is the problem, but you definitely need to make sure you are running on 1.9.2 before troubleshooting any further.
Did you install RVM? If so, have you set the default ruby? Try typing "rvm info" at the prompt. If you have RVM installed, it will print out a bunch of useful info about your ruby version. If you don't, it will say command not found. If you do have it, then you can select a different ruby version using "rvm use 1.9.2".
If you don't have RVM installed, then there are probably two versions manually installed on your host, and you'll need to figure out why rails is using 1.9.1.
In any case, I highly recommend using RVM. https://rvm.io.

Is the current Rails 3.0.5 and Bundler dependency set wrong?

On Windows 7 with Ruby 1.9.2-p180 and Rails 3.0.5 installed, if I
rails new trytry
cd trytry
bundle install
it will show
C:\ror\trytry>bundle install
c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/ui.rb:46:in `<class:UI>': uninitialized constant Gem::SilentUI (NameError)
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/ui.rb:2:in `<module:Bundler>'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/ui.rb:1:in `<top (required)>'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/cli.rb:17:in `initialize'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/vendor/thor.rb:246:in `new'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/vendor/thor.rb:246:in `dispatch'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/lib/bundler/vendor/thor/base.rb:389:in `start'
from c:/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.0/bin/bundle:13:in `<top (required)>'
from c:/Ruby192/bin/bundle:19:in `load'
from c:/Ruby192/bin/bundle:19:in `<main>
only after a
gem install bundler
or probably a
gem update bundler
then the bundle install will work. So looks like the Rails 3.0.5 needs a newer bundler which was not listed correctly in the dependency? Otherwise when I gem install rails for 3.0.5, it should have updated bundler as well, is that right?
You've got an older version of Bundler installed, you will need to run gem install bundler to update it to the latest version.
Rails depends on a version of Bundler matching the dependency version of ~> 1.0. If you've got a version of Bundler installed, such as 1.0.0, the process of gem install rails sees this dependency is matched already and so won't update Bundler. Therefore, you need to run gem install bundler to update it to the latest version.

uninitialized constant Bundler (NameError) with rails 3

When I try to run some rspec test cases I'm getting this error
I'm using linux rails 3.0.0, ruby 1.9.2 (with RVM)
config/boot.rb:8: uninitialized constant Bundler (NameError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' ..
But when do a gem list , it shows both
builder (2.1.2)
bundler (1.0.10)
so what can be the problem?
Just update your bundler, in latest version such issue is resolved.
'gem install bundler'
and then 'bundler install'
If you find again error, then delete GEM.lock file, then run bundler install. It may resolve the issue.