hi philip so i should use a loop while [email protected]? in the task create action(until its valid?)? thx
On Mon, Aug 15, 2011 at 4:29 PM, Philip Hallstrom <[email protected]> wrote: >> i was wondering how this should be handled.imagine i have this class: >> >> class Invoice < ActiveRecord::Base >> before_create :setuniqueno >> validates_uniqueness_of :uniquenumber >> def setuniqueno >> self.uniquenumber = Time.now.to_i >> end >> end >> ###### >> class Task<ActiveRecord::Base >> end >> ###### >> after the user post to the create function i also create an Invoice. >> what is not 100% clear to me, is what happens/how should i handle the >> case if the uniquenumber is not unique? eg if multiple user generate >> the same Timestamp >> how does the task-controller get feedback from the Invoice-Model? >> im doing a find_or_create_by in the create action of the task. > > In your controller, assuming you have an @invoice variable you can call > @invoice.valid? on it to see if it was found/created successfully. > > -philip > > -- > 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. > > -- 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.

