I apologize if this is a very simple question; I’ve searched the forums,
wiki, Google, and Agile Web D. with Rails to no avail.
Is there a way to put conditional validation in the model? For
instance, if I want to limit items a user can add unless the user is an
admin? My current code is:
validates_uniqueness_of :user_id, :scope => ‘event_id’,
:message => ‘You have already uploaded an item for this event.’
And I need to add something that overrides that requirement if
user.account_type == ‘admin’.
I’m also running into a problem where I need my admin users to be able
to edit other user’s information (and items) without becoming the new
“owner” of that item/user. I think this is a conceptual problem on my
part, but if someone could give me a pointer as to how you have two
instances of the same model open (the current user and the user being
edited) it would be much appreciated. I’m having the same problem with
a search box that appears on the same page as an individual item – even
if I hard-code the search form values in as blank, Rails is overwriting
it and filling the current item’s values in the search box. But I can’t
just rename the fields because they’re what’s used for search!
Thank you in advance for any assistance.