harper wrote:
> If you give an > example of what you are trying to do in the model, we may be able to > point you in the right direction.
Thanks for the reply...i wanted to give the admin of the site a possibility to see the pages that were marked unpublished, that for regular users, were impossible to see.
((publish - tinyint(1) column for any page in the Page model, that marks whether the page is published or unpublished. only the published are seen by everyone))
to do this, i found a great (with_scope) method, that gives me exactly what i wanted,
def self.find(*args) if !@session['user'] ### errors populated here self.with_scope(:find => { :conditions => "publish=1" }) do super(*args) end else super(*args) end end
except, now i get nil errors from the session variable in the first part of the clause. how do get this working, if i need to check the session to see if it is the admin, but can't use the session in the model? can/should this be defined in the controller? either way, much appreciation your way...thanks,
harp
-- Posted via http://www.ruby-forum.com/.
There are a couple of plugins floating around that also need to pull the user id from the session, so far i've seen two ways to do it.
The first is to put a before_filter in the Application controller that sets a User class variable to the current user id. The other uses a Thread local variable.
The first one works fine in most cases, but would probably break if Rails ever becomes threaded.
class User cattr_accessor :current_user .... end
--- application.rb --- before_filter :set_current_user
def set_current_user User.current_user = session['user'] end
The current user will get set at the beginning of each request, so you can be sure that it will be correct.
_Kevin