0

Somewhat simple quetion I think, but didn't really find an answer on google..

What I want is set the current_user for a model.. So I can do different validations per user..

Something like this:

var current_user # <= this is what i need

validates, :something, :presence => { :if => :current_user_is_admin? } 

def current_user_is_admin?
    current_user.user_type == 1
end

So in the controller I can set the current_user before saving the record..

Hope it makes sense..

Thanks!

1 Answer 1

3

"var" doesn't really make sense, because of Ruby's slapdash style. attr_accessor may be what you want:

attr_accessor :current_user

that defines a reader and a writer method for current_user.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.