# Login Engine and current\_user

**URL:** <https://www.ruby-forum.com/t/login-engine-and-current-user/100296>\
**Category:** Engines\
**Created:** [July 28, 2006, 7:06am UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296 "2006-07-28T07:06:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [July 28, 2006, 7:06am UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/1 "2006-07-28T07:06:53Z")

</div>

This is likely a painfully newbie-ish question, so please bare with me  
🙂

I’m muddling through my first rails application, and decided to use the  
Login Engine to handle user authentication. Now, according to the  
README, I should be able to “use current\_user method provided by  
UserHelper”, like so:

```
      Welcome <%= current_user.name %>

```

I’ve put that line in my application.rhtml, and return the following  
error:

```
undefined local variable or method `current_user' for

```

#\<#Class:0xb7875280:0xb7875258\>

which seems to suggest I haven’t done something correctly.

Now, I can find where current\_user is set in  
vendor/plugins/login\_engine/lib/login\_engine/authenticated\_system.rb

I’m still trying to work out what goes where in rails, but I figured in  
order for the method to be available globally, I needed to move that  
definition into app/controllers/application.rb. Still received the same  
error, however.

I then tried adding the definition for current\_user to  
app/helpers/application\_helper.rb, and that sort of did the trick.  
“Welcome \<%= current\_user.name %\>” now translates properly in my layout.

My real goal, however, is to get usermonitor to work  
([http://wiki.rubyonrails.org/rails/pages/Howto+Add+created\_by+and+updated\_by/versions/7](http://wiki.rubyonrails.org/rails/pages/Howto+Add+created_by+and+updated_by/versions/7)),  
and current\_user still does not appear to be accessible by this module.  
When I attempt to edit an object in one of my models, I get the error:

```
undefined method `current_user' for User:Class

```

So I gather app/helpers/application\_helper.rb is likewise not the  
correct place for this.

I then try putting it in config/environment.rb (which seems even less  
likely, though at this point I do have to concede ‘what do I know?’),  
which also appears to work as far as my application.rhtml is concerned.  
But when I try to edit an object, I now get:

```
private method `current_user' called for User:Class

```

This feels a bit like progress, but I’m stumped regarding how to make  
this method public (and whether or not that’s really what I want to do).  
If I understand things correctly, methods _are_ public by default, and  
only become private when “private” is placed before their definition?  
Which is fine, except that there is no instance of “private” in my  
config/environment.rb

At this point, I’m stumbling blind, and don’t know if I’m even remotely  
headed in the right direction. If somebody could give me a nudge in that  
right direction, I would be so very grateful!

Thanks in advance,

Gwen

---

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [July 28, 2006, 12:14pm UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/2 "2006-07-28T12:14:57Z")

</div>

Did you follow the README, particularly the lines talking about adding  
certain include lines to ApplicationHelper?

- james

---

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [July 28, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/3 "2006-07-28T16:49:32Z")

</div>

James A. wrote:

> Did you follow the README, particularly the lines talking about adding  
> certain include lines to ApplicationHelper?

Thank you for the response!

I installed the Login Engine per the instructions in the README, yes. If  
by “certain include lines to ApplicationHelper”, you mean

```
    include LoginEngine

```

I did indeed add it. If there are multiple lines to be added, I am  
definitely missing them. I just tried grepping the README file, and am  
only coming up with that one include.

The problem may actually be with usermonitor, rather than with  
login\_engine ☹

The full trace, if it offers any additional clues, is:

NoMethodError in ClientsController#update

undefined method `current\_user’ for User:Class  
RAILS\_ROOT: …/config/…

Application Trace | Framework Trace | Full Trace  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/base.rb:1129:in  
`method_missing' #{RAILS_ROOT}/lib/usermonitor.rb:24:in`update’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/base.rb:1718:in  
`create_or_update_without_callbacks' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.rb:249:in`create\_or\_update’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/base.rb:1392:in  
`save_without_validation' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/validations.rb:724:in`save\_without\_transactions’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/transactions.rb:126:in  
`save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:126:in`transaction’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/transactions.rb:91:in  
`transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:118:in`transaction’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/transactions.rb:126:in  
`save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1439:in`update\_attributes’  
#{RAILS\_ROOT}/app/controllers/clients\_controller.rb:39:in `update' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/base.rb:910:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_controller/base.rb:910:in  
`perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/filters.rb:368:in`perform\_action\_without\_benchmark’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/benchmarking.rb:69:in`measure’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/rescue.rb:82:in`perform\_action’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_controller/base.rb:381:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/base.rb:381:in`process\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_controller/filters.rb:377:in  
`process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/session_management.rb:117:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/dispatcher.rb:38:in  
`dispatch’  
dispatch.cgi:10  
EOT

Gwen

---

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [July 28, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/4 "2006-07-28T16:49:34Z")

</div>

I think this is something to do with the user monitor - the login  
engine doesn’t add any ‘current\_user’ method to the User model at  
all…

- james

---

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [August 10, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/5 "2006-08-10T22:33:50Z")

</div>

> I’m muddling through my first rails application, and decided to use the  
> Login Engine to handle user authentication. Now, according to the  
> README, I should be able to “use current\_user method provided by  
> UserHelper”, like so:
> 
> ```
> Welcome <%= current_user.name %>
> 
> ```
> 
> I’ve put that line in my application.rhtml, and return the following  
> error:

Bit of a late reply but I just ran into the exact same problem.

The LoginEngine README is _wrong_. There is no “name” field for  
current\_user. Use current\_user.login instead and it will work just fine.

Carl

---

<div class="post-metadata">

**Author:** ![gwen\_campbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@gwen\_campbell](https://www.ruby-forum.com/u/gwen_campbell)\
**Post date:** [July 28, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/login-engine-and-current-user/100296/6 "2006-07-28T17:23:13Z")

</div>

James A. wrote:

> I think this is something to do with the user monitor - the login  
> engine doesn’t add any ‘current\_user’ method to the User model at  
> all…

That explains it then 🙂 I thought that login\_engine did add a  
‘current\_user’ method to the User model (I was misunderstanding the bit  
from the README which read “You can also use the ‘current\_user’ method  
provided by UserHelper”). I see my mistake now, though – a helper  
method is available to _views_ not _models_.

So I do still need to add the method to my model. This I can do 🙂

Thanks again for your help!

Gwen
