create a new model raise error - ruby-on-rails

I am working on a Rails V2.3.2 project, I wanna create a new model, so I run the following command:
rails generate model cars name:string owner:string description:text
But I got the following error:
/home/myname/.rvm/gems/ree-1.8.7-2011.03#myapp/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from /home/myname/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `gem_original_require'
from /home/myname/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `require'
from /home/myname/.rvm/gems/ree-1.8.7-2011.03#myapp/gems/activesupport-2.3.2/lib/active_support.rb:56
...
How to get rid of this error?
P.S.
I have the code:
require 'thread'
require File.join(File.dirname(__FILE__), 'boot')
in my RakeFile , config/engironment.rb and script/server.rb

In Rails 2, the generate command is:
ruby script/generate model car name:string owner:string description:text
rails generate is the command used in Rails 3
Also, models are singular by convention (use car instead of cars. It will avoid much head-ache afterwards).

Try to insert this code before boot.rb inside Rakefile, config/environment.rb, script/server:
require 'thread'
require File.join(File.dirname(__FILE__), 'boot')
If you still get the error above you can also add require 'thread' in your boot.rb after the RAILS_ROOT constant was defined:
RAILS_ROOT = "#{File.dirname(FILE)}/.." unless defined?(RAILS_ROOT)
require 'thread'
Also watch this post: Gem 1.5 with Rails 2.3.x

Related

How To Use Spree Route Helpers in RSpec

I am trying to use the Spree 2.3 route helpers in Rspec 3.0. In the main app, I can access them by prefixing spree., like so:
spree.admin_login_path => 'spree/admin/user_sessions#new'
However I can't seem to access them in Rspec.
#rspec error
undefined local variable or method `spree_admin_login_path'
I've found reference to including the helpers in the rails_helper file, but this throws an error
# app/spec/rails_helper.rb
RSpec.configure do |config|
config.include Spree::Core::UrlHelpers
end
# configuring the above results in the following
app/spec/rails_helper.rb:21:in `block in <top (required)>': uninitialized constant Spree (NameError)
How do I access the spree routes given in $ rake routes in my tests?
After digging through the Spree code I was able to put together this setup for my rails_helper file that lets me use spree routes such as spree.admin_login_path in my spec files:
# app/spec/rails_helper.rb
require 'spree/testing_support/url_helpers'
RSpec.configure do |config|
config.include Spree::TestingSupport::UrlHelpers
end
I'm sure there's a smoother way to include all of Spree's test helpers, and I'd love to hear about it from someone who knows.

NameError: uninitialized constant Rails with Rails.root in rails 3.2

I am getting following error while executing environment.rb
C:\RailsProject>jruby script/delayed_job start
NameError: uninitialized constant RAILS_ROOT
const_missing at org/jruby/RubyModule.java:2647
(root) at C:/RailsProject/config/environment.rb:20
require at org/jruby/RubyKernel.java:1062
(root) at script/delayed_job:3
environment.rb contains following code
# Be sure to restart your server when you modify this file
require "rubygems"
require 'memcache'
if ENV['LOCAL'] == 'Y'
require "bundler/setup"
end
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['Rails.env'] = 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '3.2.13' unless defined? RAILS_GEM_VERSION
ENABLE_FACEBOOK = false
# Bootstrap the Rails environment, frameworks, and default configuration
Dir["#{Rails.root}/lib/integration/*.rb"].each do | file|
require file
end
# Initialize the rails application
RailsProject::Application.initialize!
I am using rails 3.2.13 version.
Could you please help me on this?

uninitialized constant Rails::Generators (NameError)

I'm updating the code for a generator that I wrote, but has been working fine until now.
When I simply rue the command
bundle exec rails g
I get the following error
/Users/mpierc200/projects/prototype_conflux/vendor/gems/itrc_client_files_generator-1.0.13/lib/itrc_client_files_generator.rb:6:in `<top (required)>':
uninitialized constant Rails::Generators (NameError)
The offending line is
class ItrcClientFilesGenerator < Rails::Generators::Base
My Rails version is
Rails 3.1.9
ruby version is
ruby 1.9.3p194
It looks like the Rails generator modules were pulled out and not automatically loaded at some point during Rails 3 development. This is probably for good reasons.
You have to include them in custom generators:
require 'rails/generators'
class ItrcClientFilesGenerator < Rails::Generators::Base
# Fancy generator code here
end

testing rails engine generator with rspec

I create a simpe gem wich include a install generator, generator works fine but now I want to test it using rspec, I foud this gem, and try to test my generator, my spec code is:
require 'genspec'
require 'rosalie'
describe :install_generator do
it "should generate model" do
subject.should generate("message.rb")
end
end
rosalie is the name of may gem, now when I run it I got an error:
/stuff/work/my_projects/rosalie/lib/rosalie/engine.rb:2:in `': uninitialized constant Rosalie::Rails (NameError)
my engine.rb code is:
module Rosalie
class Engine < Rails::Engine
initializer "rosalie.models.messageable" do
ActiveSupport.on_load(:active_record) do
include Rosalie::Models::Messageable
end
end
end
end
anybody can help me with this problem?
You have to load your code before you include it somewhere.
Either require or autoload your main file.
Here is an example from my gem.
You need add these code in your spec_helper.rb, and require the spec_helper in each spec.
require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'

Install omniauth rails 2.3.4

I have a rails 2.3.4 app that I'd like to extend with omniauth (0.1.5). When I install omniauth gem using rvm and place require 'omniauth' in the config.rb file I get the following error:
`gem_original_require': no such file to load -- omniauth (MissingSourceFile)
The tutorials suggest using putting it in the gemfile but I am using rails 2.
When I 'gem list' omniauth is available however.
This has taken a couple of (hair-pulling) days and I am not sure how to proceed.
Am I placing the require in the correct place or is there somewhere else I could put it (aside form the obvious :-))?
Any ideas would be great....
EDIT 1: I tried config.gem "omniauth" in your environments.rb file and got
/home/mcaulejj/explorer/config/environment.rb:10: undefined local variable or method `config' for main:Object (NameError)
EDIT 2: Using RVM I updated all gems but I am still getting the same error.....
I'm exasperated at this point.
Cheers Slothihtype
Try config.gem "omniauth" in your environments.rb file.
EDIT
As per comment,
try:
require File.join(File.dirname(__FILE__), 'boot')
#insert the following here, in your config/environment.rb
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
Add require 'oa-oauth' in your environment.rb file

Resources