On Nov 19, 2:42 pm, Rasmus Nielsen <[EMAIL PROTECTED]>
wrote:
> Hi there,
>
> I have this model called InventoryItem. Every time an InventoryItem is
> created (through the CharactersController and the create_item action) I
> need to update others tables and make lookups in other tables, to check
> if the Character has the prerequisites to actually create the
> InventoryItem.

I think validate_on_create is where you want to ensure that it's ok to
create the InventoryItem.

Then use before_create to actually do the work of updating the related
models.  It's only called if all the validations pass.

> My problem is that I cannot seem to find a good place to put this logic.
> I've tried to put it in a InventoryItem#validate_on_create. This is a
> hassle, because the InventoryItem has no direct association to all the
> things it need to check/update.

Why not?  Sounds like an InventoryItem is associated to a Character,
and so you should have access to all of Character's related tables as
well.  Maybe I'm missing something about the way you've setup your
models?

Jeff

purpleworkshops.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to