Forum: Rails Engines rake bootstrap --trace: undefined method `roles' for #<User:

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg D. (Guest)
on 2006-02-15 07:05
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:in
`method_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:in `execute'
/usr/lib/ruby/1.8/rake.rb:202:in `invoke'
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:195:in `invoke'
/usr/lib/ruby/1.8/rake.rb:209:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:844:in `each'
/usr/lib/ruby/1.8/rake.rb:208:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:201:in `invoke'
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:195:in `invoke'
/usr/lib/ruby/1.8/rake.rb:1719:in `run'
/usr/lib/ruby/1.8/rake.rb:1719:in `run'
/usr/bin/rake:4
Greg D. (Guest)
on 2006-02-16 02:47
In addition I'm getting this error in my main controller:

NoMethodError in Home#index

undefined method `guest_user_authorized?' for User:Class
James A. (Guest)
on 2006-02-16 17:46
(Received via mailing list)
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:in `run'
> /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...
>


--
* J *
  ~
James A. (Guest)
on 2006-02-16 17:46
(Received via mailing list)
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 *
  ~
James A. (Guest)
on 2006-02-16 17:49
(Received via mailing list)
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...
>


--
* J *
  ~
Greg D. (Guest)
on 2006-02-16 17:50
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.
Greg D. (Guest)
on 2006-02-16 17:51
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.
Greg D. (Guest)
on 2006-02-16 17:55
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.
James A. (Guest)
on 2006-02-16 17:58
(Received via mailing list)
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...
>


--
* J *
  ~
Jim K. (Guest)
on 2006-02-16 23:29
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...
>>
>
>
> --
> * J *
>   ~
Jim K. (Guest)
on 2006-02-17 00:28
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:in
`method_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
Greg D. (Guest)
on 2006-02-17 00:53
(Received via mailing list)
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/
Greg D. (Guest)
on 2006-02-17 05:44
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' )
Jim K. (Guest)
on 2006-02-20 19:59
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
Surendra S. (Guest)
on 2006-02-23 21:35
(Received via mailing list)
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
`----
Guest (Guest)
on 2006-07-10 13:50
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.
This topic is locked and can not be replied to.