# How to use current\_user in tags

**URL:** <https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443>\
**Category:** Radiant CMS\
**Created:** [October 21, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443 "2008-10-21T15:44:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [October 21, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443/1 "2008-10-21T15:44:20Z")

</div>

Hello,

I need to use the current\_user in Radius tags. In fact it is working on  
my computer which is running with MAC OS (and previously on my Windows  
environment), but not on my friend computer which is on Windows.

Well, what I have done :

1. create an accessor attribut ‘current\_user’ on page model
2. extended site\_controller to give the current user to my current page  
:  
@page.current\_user = current\_user
3. Then, on my tags I’m using current\_user like that :  
tags.local.page.current\_user

And it is working on my computer. We have exactly the same project and  
same database… has anyone any idea on what could broke the process? In  
fact tags.local.page.current\_user is nil on my computer’s friend.

I will copy his and my gems list :

=============================  
His :

ctionmailer (2.1.0)  
Service layer for easy email delivery and testing.

actionpack (2.1.0, 1.13.6)  
Web-flow and rendering framework putting the VC in MVC.

actionwebservice (1.2.6)  
Web service support for Action Pack.

activerecord (2.1.0, 1.15.6)  
Implements the ActiveRecord pattern for ORM.

activeresource (2.1.0)  
Think Active Record for web resources.

activesupport (2.1.0, 1.4.4)  
Support and utility classes used by the Rails framework.

cgi\_multipart\_eof\_fix (2.5.0)  
Fix an exploitable bug in CGI multipart parsing.

ferret (0.11.5)  
Ruby indexing library.

fxri (0.3.6)  
Graphical interface to the RI documentation, with search engine.

fxruby (1.6.12)  
FXRuby is the Ruby binding to the FOX GUI toolkit.

gem\_plugin (0.2.3)  
A plugin system based on rubygems that uses dependencies only

haml (2.0.1)  
An elegant, structured XHTML/XML templating engine. Comes with Sass,  
a similar CSS templating engine.

hpricot (0.6)  
a swift, liberal HTML parser with a fantastic library

htmlentities (4.0.0)  
A module for encoding and decoding (X)HTML entities.

json (1.1.1)  
A JSON implementation as a Ruby extension

log4r (1.0.5)  
Log4r is a comprehensive and flexible logging library for Ruby.

mime-types (1.15)  
Manages a MIME Content-Type that will return the Content-Type for a  
given filename.

mislav-will\_paginate (2.3.5)  
Most awesome pagination solution for Rails

mongrel (1.1.2)  
A small fast HTTP library and server that runs Rails, Camping, Nitro  
and Iowa apps.

mysql (2.7.3)  
A win32-native build of the MySQL API module for Ruby.

radiant (0.6.9)  
A no-fluff content management system designed for small teams.

rails (2.1.0)  
Web-application framework with template engine, control-flow layer,  
and ORM.

rake (0.8.1, 0.7.3)  
Ruby based make-like utility.

RedCloth (3.301)  
a fast library for formatting Textile as HTML

rflickr (2006.02.01)  
Ruby interface to the Flickr API

rmagick (2.5.0)  
RMagick is an interface between the Ruby programming language and  
ImageMagick.

ruby-debug-base (0.10.0)  
Fast Ruby debugger - core component

ruby-debug-ide (0.1.10)  
IDE interface for ruby-debug.

ruby-openid (2.1.2)  
A library for consuming and serving OpenID identities.

solr-ruby (0.0.6)  
Ruby library for working with Apache Solr

sources (0.0.1)  
This package provides download sources for remote gem installation

sqlite3-ruby (1.2.1)  
SQLite3/Ruby is a module to allow Ruby scripts to interface with a  
SQLite database.

win32-api (1.0.4)  
A superior replacement for Win32API

win32-clipboard (0.4.3)  
A package for interacting with the Windows clipboard

win32-dir (0.3.2)  
Extra constants and methods for the Dir class on Windows.

win32-eventlog (0.4.6)  
Interface for the MS Windows Event Log.

win32-file (0.5.4)  
Extra or redefined methods for the File class on Windows.

win32-file-stat (1.2.7)  
A File::Stat class tailored to MS Windows

win32-process (0.5.3)  
Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method

win32-sapi (0.1.4)  
An interface to the MS SAPI (Sound API) library.

win32-sound (0.4.1)  
A library for playing with sound on MS Windows.

win32console (1.1.0)  
A library giving the Win32 console ANSI escape sequence support.

windows-api (0.2.0)  
An easier way to create methods using Win32API

windows-pr (0.7.2)  
Windows functions and constants bundled via Win32::API

=============================  
Mine :  
actionmailer (2.1.1, 1.3.6)  
actionpack (2.1.1, 1.13.6)  
actionwebservice (1.2.6)  
activerecord (2.1.1, 1.15.6)  
activeresource (2.1.1)  
activesupport (2.1.1, 1.4.4)  
acts\_as\_ferret (0.4.1)  
capistrano (2.0.0)  
cgi\_multipart\_eof\_fix (2.5.0, 2.2)  
daemons (1.0.9, 1.0.7)  
dnssd (0.6.0)  
fastthread (1.0.1, 1.0)  
fcgi (0.8.7)  
ferret (0.11.4)  
gem\_plugin (0.2.3, 0.2.2)  
highline (1.2.9)  
hpricot (0.6)  
libxml-ruby (0.3.8.4)  
mislav-will\_paginate (2.3.5)  
mongrel (1.1.4, 1.0.1)  
needle (1.3.0)  
net-sftp (1.1.0)  
net-ssh (1.1.2)  
rails (2.1.1, 1.2.6)  
rake (0.8.3, 0.7.3)  
RedCloth (3.0.4)  
ruby-openid (1.1.4)  
ruby-yadis (0.3.4)  
rubynode (0.1.3)  
solr-ruby (0.0.6)  
sources (0.0.1)  
sqlite3-ruby (1.2.1)  
termios (0.9.4)  
will\_paginate (2.2.2)

Thank you very much !  
Vincent

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [October 21, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443/2 "2008-10-21T16:43:59Z")

</div>

Vincent PÃ©rÃ¨s wrote:

> @page.current\_user = current\_user  
> 3. Then, on my tags I’m using current\_user like that :  
> tags.local.page.current\_user
> 
> And it is working on my computer. We have exactly the same project and  
> same database… has anyone any idea on what could broke the process? In  
> fact tags.local.page.current\_user is nil on my computer’s friend.

Vincent,

Is your friend logged in to the admin site? Also, did you re-enable  
sessions in the SiteController?

Sean

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [October 21, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443/3 "2008-10-21T17:16:01Z")

</div>

Hello Sean,

I didn’t enabled session, I created a new page type which is not using  
cache.  
In fact, the problem is on site\_controller level, when I’m giving the  
current user to my current page :  
@page.current\_user = current\_user

On my computer ‘current\_user’ exist, but the var is nil on the other  
computer.  
What could enabled or disabled current\_user? (it’s a helper if I  
remember well)

Thanks,  
Vincent

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [October 22, 2008, 9:59am UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443/4 "2008-10-22T09:59:34Z")

</div>

Yes, he is logged in (sure).  
To access to the current\_user, I added a line on the  
file\_based\_extension (butI’m not using this extension yet) :

module FileBasedLayout  
module SiteControllerExt  
def self.included(base)  
base.class\_eval {  
include InstanceMethods  
alias\_method\_chain :process\_page, :file\_based\_layout  
}  
end

```
module InstanceMethods

  protected

  def process_page_with_file_based_layout(page)
    @page.current_user = current_user
    puts " ****************** session : " + session.inspect
    if @page.layout && @page.layout.file_based?
      render :text => process_with_file_based_layout(@page), :layout 

```

=\> @page.layout.layout\_file.gsub(/(.[a-z]+)?.[a-z]+$/, ‘’)  
else  
process\_page\_without\_file\_based\_layout(page)  
end  
end  
etc.

current\_user and session are not empty on my computer, but they are nil  
on the other one… I’m realy lost because we have the same mysql dump  
and project files.

If I can’t resolve my problem, there is an other way to access to my  
current user/user\_id ?

Thank you !  
Vincent

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [October 21, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/how-to-use-current-user-in-tags/151443/5 "2008-10-21T17:33:28Z")

</div>

Vincent,

The helper is there regardless. However, current\_user will only be  
populated _if the user is logged in_. To enable sessions, add this to  
your extension, in the activate method:

SiteController.class\_eval { session :disabled =\> false }

Sean
