Rake bootstrap --trace: undefined method `roles' for #<User:


#1

rake bootstrap --trace

dies with:

** Invoke bootstrap (first_time)
** Invoke sync_permissions (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sync_permissions
** Invoke create_roles (first_time)
** Invoke environment
** Execute create_roles
** Invoke create_admin_user (first_time)
** Invoke environment
** Execute create_admin_user
rake aborted!
undefined method roles' for #<User:0xb7633288> /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1501:inmethod_missing’
./vendor/plugins/user_engine/tasks/user_engine.rake:30
/usr/lib/ruby/1.8/rake.rb:232:in execute' /usr/lib/ruby/1.8/rake.rb:232:inexecute’
/usr/lib/ruby/1.8/rake.rb:202:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/1.8/rake.rb:195:in invoke' /usr/lib/ruby/1.8/rake.rb:209:ininvoke_prerequisites’
/usr/lib/ruby/1.8/rake.rb:844:in each' /usr/lib/ruby/1.8/rake.rb:208:ininvoke_prerequisites’
/usr/lib/ruby/1.8/rake.rb:201:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/1.8/rake.rb:195:in invoke' /usr/lib/ruby/1.8/rake.rb:1719:inrun’
/usr/lib/ruby/1.8/rake.rb:1719:in `run’
/usr/bin/rake:4


#2

In addition I’m getting this error in my main controller:

NoMethodError in Home#index

undefined method `guest_user_authorized?’ for User:Class


#3

Can you confirm that you’ve run ‘rake engine_migrate
ENGINE=user_engine’, or just ‘rake engine_migrate’ after installing
the user engine? In other words, do you definitely have the user
engine database tables?

  • james

On 2/15/06, Greg D. removed_email_address@domain.invalid wrote:

** Invoke create_roles (first_time)
/usr/lib/ruby/1.8/rake.rb:232:in execute' /usr/lib/ruby/1.8/rake.rb:1719:inrun’
/usr/lib/ruby/1.8/rake.rb:1719:in `run’
/usr/bin/rake:4


Posted via http://www.ruby-forum.com/.


engine-users mailing list
removed_email_address@domain.invalid
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

#4

Also, which verson of Rails are you using?

On 2/16/06, James A. removed_email_address@domain.invalid wrote:

** Invoke create_admin_user (first_time)
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize’

  • J *
    ~

  • J *
    ~

#5

It sounds very much like you haven’t properly installed the user
engine. Did you follow the user engine README file step by step?

It’s also possible that your version of Rails (1.0? InstantRails?
Locomotive?) isn’t playing nice with the engines plugin. Be sure to
update to the latest release (or the SVN trunk if you’re using edge
rails, there are a few more hoops to jump through, check this list’s
archives).

  • james

On 2/16/06, Greg D. removed_email_address@domain.invalid wrote:

engine-users mailing list
removed_email_address@domain.invalid
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

#6

James A. wrote:

Can you confirm that you’ve run ‘rake engine_migrate
ENGINE=user_engine’, or just ‘rake engine_migrate’ after installing
the user engine? In other words, do you definitely have the user
engine database tables?

I have run ‘rake engine_migrate’ successfully. I see several new tables
were created in my database.


#7

James A. wrote:

Also, which verson of Rails are you using?

Rails 1.0 and I also tried for a brief period with Edge Rails.


#8

James A. wrote:

It sounds very much like you haven’t properly installed the user
engine. Did you follow the user engine README file step by step?

I did a complete install twice, engines, login_engine, user_engine, same
errors both times. Seems like something is loading out of order.

It’s also possible that your version of Rails (1.0? InstantRails?
Locomotive?) isn’t playing nice with the engines plugin.

No idea, since I’ve never seen this work before I have no idea what is
supposed to be playing with what.

Be sure to
update to the latest release (or the SVN trunk if you’re using edge
rails, there are a few more hoops to jump through, check this list’s
archives).

I have tried with Rails 1.0 and Edge Rails. Searching for the error
messages returned no results, so I posted.


#9

Hi all, I am having the same problem that Greg originally described
(undefined method: ‘foo’ during the running of the bootstrap), in
addition to getting

NoMethodError: undefined method ‘guest_user_authorized?’ for User::Class

if I brute-force my way past the bootstrap errors by setting the role
<-> permission link manually in the DB. I concur with him that it looks
like the overrides for the User Class aren’t being loaded, but I don’t
know why. I’ve tried all of the possible ways to specify engine loading
in environment.rb, and none of them make a difference. I get the same
NoMethodError when I try to get something out of ‘User.roles’ in the
console. I have had a working Login Engine installation in the app for
a week or two, so I’m pretty sure that part is solid. All of the
necessary tables also appear to be in place and populated.

I hope something in my rambling helps jog your memory or push you in the
direction of whatever might by amiss here.

Jim

James A. wrote:

In a console, can you get and sensible output from

User.roles

or

UserEngine::AuthorizedUser

?

I’m just checking to see if the user engine has been loaded or not.
Oh, also check that you’ve got Engines.start :login, :user in your
environment.rb file…

  • james

On 2/16/06, Greg D. removed_email_address@domain.invalid wrote:

removed_email_address@domain.invalid
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

#10

In a console, can you get and sensible output from

User.roles

or

UserEngine::AuthorizedUser

?

I’m just checking to see if the user engine has been loaded or not.
Oh, also check that you’ve got Engines.start :login, :user in your
environment.rb file…

  • james

On 2/16/06, Greg D. removed_email_address@domain.invalid wrote:

removed_email_address@domain.invalid
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

#11

Jim K. wrote:

Hi all, I am having the same problem that Greg originally described
(undefined method: ‘foo’ during the running of the bootstrap), in
addition to getting
And of course, now I’ll reply to myself with all of the info I should
have included the first time:

I’m running Rails 1.0 and what appears to be the latest rev of Login and
User engines
I’ve tried it on Windows and OS X with the same results both places
in the console (in response to your second query):

User.roles
NoMethodError: undefined method roles' for User:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:991:inmethod_missing’
from (irb):3

UserEngine::AuthorizedUser
=> UserEngine::AuthorizedUser

So it knows a little something about the user engine, but it doesn’t
seem to get everything loaded right. I did notice one oddity in the
engine docs, but I’m still a bit too green to know if it’s relevant.
The Login Engine docs mention adding “require ‘login_engine’” to the top
of app/controllers/application.rb. However, the user engine docs don’t
show this. I think I tried several different permutations without
success, but I could have been flailing at that point.

Jim


#12

On 2/16/06, Jim K. removed_email_address@domain.invalid wrote:

Hi all, I am having the same problem that Greg originally described

Trying this on a second Debian box I can complete the login_engin
install but then get errors with the user_engine install:

rake engine_migrate
(in /home/gcdonald/rails/engine_test)
Migrating engine ‘login_engine’
SQL (0.000000) ERROR: relation “schema_info” already exists
: CREATE TABLE schema_info (version integer)
SQL (0.000000) ERROR: relation “engine_schema_info” already exists
: CREATE TABLE engine_schema_info (engine_name character varying(255),
version integer)
SQL (0.000000) ERROR: relation “schema_info” already exists
: CREATE TABLE schema_info (version integer)
SQL (0.000000) ERROR: relation “engine_schema_info” already exists
: CREATE TABLE engine_schema_info (engine_name character varying(255),
version integer)
SQL (0.002690) SELECT version FROM engine_schema_info WHERE
engine_name = ‘login_engine’

I also tried:

rake engine_migrate ENGINE=user
(in /home/gcdonald/rails/engine_test)
Couldn’t find an engine called ‘user’

which is very odd since I didn’t get any errors when I did:

svn co http://opensvn.csie.org/rails_engines/plugins/user_engine vendor/plugins/user_engine

and I can confirm there is a user_engine installed in vendor/plugins:

ls -lah vendor/plugins/user_engine/
total 20K
drwxr-xr-x 9 gcdonald gcdonald 272 2006-02-16 16:34 .
drwxr-xr-x 5 gcdonald gcdonald 136 2006-02-16 16:34 …
drwxr-xr-x 7 gcdonald gcdonald 176 2006-02-16 16:34 app
drwxr-xr-x 4 gcdonald gcdonald 128 2006-02-16 16:34 db
-rw-r–r-- 1 gcdonald gcdonald 1.4K 2006-02-16 16:34 init_engine.rb
drwxr-xr-x 4 gcdonald gcdonald 136 2006-02-16 16:34 lib
drwxr-xr-x 5 gcdonald gcdonald 136 2006-02-16 16:34 public
-rw-r–r-- 1 gcdonald gcdonald 13K 2006-02-16 16:34 README
drwxr-xr-x 7 gcdonald gcdonald 328 2006-02-16 16:34 .svn
drwxr-xr-x 3 gcdonald gcdonald 104 2006-02-16 16:34 tasks
drwxr-xr-x 6 gcdonald gcdonald 184 2006-02-16 16:34 test

I also tried removing all the tables that were created during the
login_engine install, but it didn’t help. I got the same errors as
with running rake engine_migrate the first time for the login_engine.


Greg D.
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/


#13

Greg D. wrote:

James A. wrote:

also check that you’ve got Engines.start :login, :user in your
environment.rb file…
That wasn’t it for me, but I did find the solution. I had created an
app/models/user.rb file some time back to hold some associations (I must
have done it right when I installed the login engine), and then promptly
forgotten about it. Removing that file caused the NoMethodErrors to
disappear. It’s always the last thing you check…

Jim


#14

James A. wrote:

also check that you’ve got Engines.start :login, :user in your
environment.rb file…

I just had Engines.start, so I tried your suggestion and it seems to
help. I’m no longer getting the missing method error.

At this point I started seeing some database issues. This error was
being logged on most every request:

Role Load (0.000000) RuntimeError: ERROR C42P01 Mrelation
“users_roles” does not exist Fnamespace.c L200 RRangeVarGetRelid:
SELECT * FROM roles LEFT JOIN users_roles ON roles.id =
users_roles.role_id WHERE (users_roles.user_id = 1 )

I didn’t have a user_roles table, but I had a _roles table. I tried
renaming it to user_roles but it didn’t seem to help even after
restarting the server. So I dropped all the tables and ran rake
engine_migrate again, then rake bootstrap again. This time I had a
user_roles table, but when I try to access a page it just sits there,
never to respond.

I’m not sure what it’s doing, but this is the last thing logged:

Role Count (0.003174) SELECT COUNT(*) FROM roles
SQL (0.006606) SELECT a.attname, format_type(a.atttypid,
a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = ‘roles’::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Role Load (0.002843) SELECT * FROM roles WHERE (roles.“omnipotent” =
‘t’ )


#15

Jim K. removed_email_address@domain.invalid writes:

Greg D. wrote:

James A. wrote:

also check that you’ve got Engines.start :login, :user in your
environment.rb file…
That wasn’t it for me, but I did find the solution. I had created an
app/models/user.rb file some time back to hold some associations (I must
have done it right when I installed the login engine), and then promptly
forgotten about it. Removing that file caused the NoMethodErrors to
disappear. It’s always the last thing you check…

Yeah, I was also facing the same problem. Luckily I found your post and
removing the user.rb file solved the problem.


Surendra S.
http://ssinghi.kreeti.com, http://www.kreeti.com
Read the latest news at: http://news.kreeti.com
,----
| “O thou my friend! The prosperity of Crime is like unto the lightning,
| whose traitorous brilliancies embellish the atmosphere but for an
| instant, in order to hurl into death’s very depths the luckless one
| they have dazzled.” – Marquis de Sade
`----


#16

I had to patch the lib\login_engine.rb and add in the users table. My
problem was that when doing a migration (rake engine_migrate) I was only
getting _roles table created:

– create_table("_roles", {:id=>false, :force=>true})

Here’s the patched code - add config: user_table … (x2)

module UserEngine

#–

These are the default constants, used if nothing else is specified

#++

The names of the new Role and Permission tables

if ActiveRecord::Base.pluralize_table_names
config :user_table, “users”
config :role_table, “roles”
config :permission_table, “permissions”
else
config :user_table, “user”
config :role_table, “role”
config :permission_table, “permission”
end

Join tables for users <-> roles, and roles <-> permissions

config :user_role_table,
“#{LoginEngine.config(:user_table)}#{config(:role_table)}"
config :permission_role_table,
"#{config(:permission_table)}
#{config(:role_table)}”

Note: this may have already been patched.