[Rails] @user.is_the_administrator
Mischa Berger
spmm_pls at yahoo.com
Thu Feb 23 19:43:27 GMT 2006
Hi,
Sorry for reposting, but my date was set 1-feb today (don't ask) and I'm
not sure if this gets read...
My question is about this method:
# 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 doing this because...
Once the admin is created I don't want anyone to be able to change the name.
I implemented this like this in the view:
<% if @user and @user.is_the_administrator %>
<%= text_field "user", "name", :disabled => true %>
<% else %>
<%= text_field "user", "name" %>
<% end %>
However when someone else tries to change their name to "admin", the
text_field will be disabled too. The object is not saved, because of the
validation (validates_uniqueness_of :name). So I only want the field to be
disabled if the object is saved. The way I implemented it now works, but
I'm
guessing there's a better way to do this.
Any ideas?
Thanks!!
More information about the Rails
mailing list