ACL9 and Rails 2.3.8 - NameError: uninitialized constant User::Role - ruby-on-rails

I am running RVM (Ruby 1.8.7-head, Rails 2.3.8) and have the BASICS of a new app running. I have Authlogic working, with the minimal code to make that work. I am attempting to use ACL9 (which I have working on a different project, same RVM gemset)
class User < ActiveRecord::Base
# authentication
acts_as_authentic
# authorization
acts_as_authorization_subject
def full_name
"#{self.first_name} #{self.last_name}"
end
end
When I attempt to just run a simple check to make sure ACL9 is working properly...
script/console
u = User.first
u.has_role?(:anyrole)
I get this error...
ruby-1.8.7-head > u.has_role?(:anyrole)
NameError: uninitialized constant User::Role
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in `const_missing'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `compute_type'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `send'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `klass'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:187:in `quoted_table_name'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:102:in `construct_sql'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:21:in `initialize'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:5:in `initialize'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `new'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `role_objects'
from /Users/development/.rvm/gems/ruby-1.8.7-head#rails238/gems/acl9-0.12.0/lib/acl9/model_extensions/for_subject.rb:39:in `has_role?'
from (irb):2
I'm not sure why this works with every other app I have, but not this one - and I'm not sure what the error message is saying.. any help is appreciated.

class Role < ActiveRecord::Base
acts_as_authorization_role
end

Related

undefined method `default' for ActionMailer

I'm having this weird error with Rails 5 action mailer.
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "from#example.com"
layout 'mailer'
end
irb
~/workspace/rails5 > rails c ruby-2.4.1#rails5
Running via Spring preloader in process 45498
Loading development environment (Rails 5.1.2)
2.4.1 :001 > ApplicationMailer
NameError: uninitialized constant Mail::TestMailer
from app/mailers/application_mailer.rb:1:in `<top (required)>'
from (irb):1
2.4.1 :002 > ApplicationMailer
NoMethodError: undefined method `default' for ApplicationMailer:Class
from app/mailers/application_mailer.rb:3:in `<class:ApplicationMailer>'
from app/mailers/application_mailer.rb:1:in `<top (required)>'
from (irb):2
2.4.1 :003 >
This is the default Scaffold of rails 5.
Two really weird things happen the first is that it always tells me the uninitialized constant then trows default is not a method right after.
Just wondering how to fix it or if I should downgrade to Rail 5.0
The solution turned out to be that if you have a model named mail the ActionMailer will grab that one first instead of the rails class. If this happens then it fails the first time but the second time will load the rails class and try and smash them together. Allowing the submodule to work but treating the main class as a monkey path.

uninitialized constant ActiveRecord

2.0.0-p247 :006 > load './app/models/user.rb'
NameError: uninitialized constant ActiveRecord
from /home/action/iAuth/app/models/user.rb:1:in `<top (required)>'
from (irb):6:in `load'
from (irb):6
from /home/action/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
Below is my User Model.
class User < ActiveRecord::Base
end
When i try to load my user.rb in my irb, i get the above error.
start your irb session with
rails console
and not:
irb
rails console would load your rails environment and your model for you, so you can do things like:
User.all or User.new without loading the class as it has been preloaded by rails console already
there's another case.
if you are using mongoid ( mongo db adapter) , and you have to make sure in config/application.rb, you must require activerecord:
require "active_model/railtie"

Sidekiq Install - uninitialized constant ActiveRecord::Base (NameError)

I am trying to integrate Sidekiq with my Rails Mongoid app. I have been following the steps as outlined Here
I also have redis & mongodb running locally. However after I run bundle then when I try to start my server I get this error....
c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:4:in `hook_rails!': uninitialized constant ActiveRecord::Base (NameError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:16:in `block in <class:Rails>'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Users/example/Documents/Workspace/app/config/environment.rb:5:in `<top (required)>'
My environment.rb file is as follows...
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
I previously had resque with redis working with mongoid in this app, so its a sidekiq issue. I don't have a database.yml file since I am using mongoid. I also added the steps for kiqstand but I am getting the same error. Unsure how to resolve?
Edit: I'm 90% sure its because Sidekiq is looking for ActiveRecord, however I removed ActiveRecord cause I'm using Mongo instead. My application.rb has...
# remove activerecord and run off of mongo only
#require 'rails/all'
#http://stackoverflow.com/a/9327651/1026266
%w(
action_controller
action_mailer
active_resource
rails/test_unit
sprockets
).each do |framework|
begin
require "#{framework}/railtie"
rescue LoadError
end
end
Now I just need to figure out how to tell sidekiq to not look for it?
Lack of ActiveRecord was the issue, looks like there was a pull request - https://github.com/mperham/sidekiq/pull/1090
But that was rejected, so I just had to add ActiveRecord to my app and add a dummy database.yml file.

uninitialized constant Test::Unit::UI::XML (NameError) in Rails (or Ruby)

I'm trying to create an xml runner to make a result report of Rails unit testing. Here is a code I have:
require 'test/unit'
require 'test/unit/ui/console/testrunner'
class FastFailRunner < Test::Unit::UI::Console::TestRunner
def add_fault(fault)
#faults << fault
nl
output("%3d) %s" % [#faults.length, fault.long_display])
output("--")
#already_outputted = true
end
def finished(elapsed_time)
nl
output("Finished in #{elapsed_time} seconds.")
nl
output(#result)
end
end
Test::Unit::AutoRunner::RUNNERS[:fastfail] = proc do |r|
FastFailRunner
end
When I run it as TESTOPTS="/home/alex/RubymineProjects/app2/test/unit/runner.rb --runner=xml" rake test
... I get an error (pretty weird error)
/home/alex/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
gem install minitest
/home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
I tried to require test/unit/ui/xml/testrunner.rb but no luck.
Any thoughts?
If you are in Ruby 1.8.7 you can say:
require 'test/unit/ui/console/testrunner'
p Test::Unit::UI::Console::TestRunner # => no problem
(There is no such file as test/unit/ui/xml/testrunner.rb so I'm not sure what you were up to there.)
Look in the docs in test/unit.rb, there's actually sample code showing you how to do this require: http://www.ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html.
However, the problem is that you are in Ruby 1.9.3. There is no /test/unit in Ruby 1.9.3! Well, there is, but it's just a compatibility layer for basic tests; there is certainly no test/unit/ui/console/testrunner, and no module/class Test::Unit::UI::Console::TestRunner.
Instead, there's minitest. You can read the docs on minitest to see how to make a test runner. http://docs.seattlerb.org/minitest/
One thing to consider is that Test::Unit was included in the default Ruby 1.8.7 installation. If you want to use it in with a later version of Ruby then go ahead and install it as a gem.
sudo gem install test-unit
http://test-unit.rubyforge.org/

uninitialized constant Active Scaffold rails 2.3.5

I update my rails application 2.0.2 to 2.3.5. I use active scaffold for the administration part.
I change nothing in my code but a problem is coming with the update.
I have a controller 'admin/user_controller' to manage users.
Here is the code of the controller:
class Admin::UserController < ApplicationController
layout 'admin'
active_scaffold :user do |config|
config.columns.exclude :content, :historique_content, :user_has_objet, :user_has_arme, :user_has_entrainement, :user_has_mission, :mp, :pvp, :user_salt, :tchat, :notoriete_by_pvp, :invitation
config.list.columns = [:user_login, :user_niveau, :user_mail, :user_bloc, :user_valide, :group_id] #:user_description, :race, :group, :user_lastvisited, :user_nextaction, :user_combats_gagner, :user_combats_perdu, :user_combats_nul, :user_password, :user_salt, :user_combats, :user_experience, :user_mana, :user_vie
config.create.link.page = true
config.update.link.page = true
config.create.columns.add :password, :password_confirmation
config.update.columns.add :password, :password_confirmation
config.create.columns.exclude :user_password, :user_salt
config.update.columns.exclude :user_password, :user_salt
config.list.sorting = {:user_login => 'ASC'}
config.subform.columns = []
end
end
This code hasn't change with the update, but when I go in this page, I got this error:
uninitialized constant Users
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in `constantize'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `each'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `constantize'
/Users/Kiva/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:28:in `reverse_matches_for'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:24:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:24:in `reverse_matches_for'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb:11:in `reverse'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb:117:in `autolink?'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:107:in `links_for_associations'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:106:in `links_for_associations'
/Users/Kiva/Documents/Projet-rpg/jeu/vendor/plugins/active_scaffold/lib/active_scaffold.rb:59:in `active_scaffold'
/Users/Kiva/Documents/Projet-rpg/jeu/app/controllers/admin/user_controller.rb:11
I search since 2 days but I don't find the problem, can you help me please.
the naming convention in your application seems buggy
it should be:
class Admin::UsersController < ApplicationController
not UserController as it is. maybe it won't fix your problem, but it worth a try!
It seems to be a problem with the way the Model is defined. I had the very same issue when accessing tables in the database with a rake backup task. The problem was that I had a table defined in the database through "belongs_to". I didn't think I needed a model for that table but constantize kept failing. Introducing the model fixed the problem.
Table : users_clients
Model : UsersClient
Starting with Rails 2.3.x you have to install the Render Component plugin:
./script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3
See instructions here: https://github.com/activescaffold/active_scaffold/wiki/getting-started

Resources