Extending SiteController -- how to get current_user

Hey guys,

I’m putting together a rudimentary extension to create member system
that will allow me to restrict certain front-end pages to certain logged
in users.

However, as this is my first real Rails attempt, I’m hitting some walls.
I have extended the Page model and the User model to work the way I
require, but I can’t get the current_user in the SiteController.

What is the proper way to access the current logged in user in a
controller? I see that LoginSystem is setting it, but I don’t really
understand where it then goes.

Sorry if this hits on some basic knowledge questions, but I’m starting
out here :slight_smile:



The current_user method used in Radiant and the member system are
probably (or should be) different things, unless all of your members
should have logins to the admin interface. However, assuming this is
not the case, you’ll need to extend the SiteController, probably using
an included module. The module would redefine/intercept various methods
in the controller. When we built something similar for Redken, we
turned on the session (using session :disabled => false), used
alias_method_chain to intercept process_page so we could pass the
current_user to the page, and added some before_filters to login from
cookies and do other similar tasks. All told, it was probably around 30
lines of code, outside of the generated user/login boilerplate.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs