Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError)

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]
like image 338
vajapravin Avatar asked Jun 18 '12 07:06

vajapravin


People also ask

What is NoMethodError in Ruby?

Raised when a method is called on a receiver which doesn't have it defined and also fails to respond with method_missing .

What does undefined method mean in Ruby?

This is a common Ruby error which indicates that the method or attribute for an object you are trying to call on an object has not been defined.

What is undefined method?

A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .

What does it mean when you get this error message undefined method user for NILClass?

The Undefined method for nil:NILClass occurs when you attempt to use a formula on a blank datapill. This indicates that the datapill was not provided any value at runtime.


4 Answers

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.

like image 168
Michael Ryan Soileau Avatar answered Oct 19 '22 04:10

Michael Ryan Soileau


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.

like image 45
vajapravin Avatar answered Oct 19 '22 04:10

vajapravin


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)
like image 4
Vishnu Atrai Avatar answered Oct 19 '22 03:10

Vishnu Atrai


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 ?

like image 7
Jeremy F. Avatar answered Oct 19 '22 02:10

Jeremy F.