Forum: Ruby on Rails Check if a saved user's name is admin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mischa B. (Guest)
on 2006-02-23 16:52
(Received via mailing list)
Hi all,

I have a question about this method in my User model:

# Returns true for the (saved) user called "admin"
def is_the_administrator
  true if save and name == "admin"
end

The method returns true if the user's name is admin. However, I only
want to
return true if the state of the object is "saved", so I call the save
method
first.

I'm wondering if there's another (better) way to make sure the object is
saved...
Is there??

Thanks,
Mischa.
gustav paul (Guest)
on 2006-02-23 18:20
If I understood you correctly, try something like this? :

def is_the_administrator
  if name == 'admin'
    true if save
  end
end

Hope this helps... :]
gustav
This topic is locked and can not be replied to.