From: Cory L. <co...@ma...> - 2008-01-29 00:32:37
|
Right now my solution is very specific to the task: #in MyProxy def rbSetValue_forKey(value, key) if key.to_s == 'upc' @record[key.to_s] = value.to_ruby rescue nil @record["price"] = 342 rescue nil result = @record.save else super(value, key) end end I figure I can revisit it once I get some other concepts tackled first. I'm a bit confused by the proxy thing. I have a something like MyClass, MyProxy, and MyController. In the controller I can create the new record, but nothing shows up in the table until I restart the app. I think this is where my understanding of the proxy is breaking down. MyController.create works fine, but any variation of MyProxy.create or something with to_activerecord_proxy just results in my loss and confusion. Do you have any suggestions on documentation? I've been picking apart the includes and examples, but that only gets me so far. Thanks for the previous suggestions. Cory On Jan 28, 2008, at 11:53 AM, Eloy Duran wrote: > Hi Cory, > > There's indeed no other way yet to do it then you have done with > rbSetValue_forKey. > There is only on_get for when data is being requested. > > I'm interested to see the code on how you did it, so we could maybe > turn it into a nicer solution. > > About creating records from your code, you can simply use the normal > way of doing this with AR. > So: Mailbox.create etc. > > But if you're gonna add it to a ActiveRecordSetController, or anything > other related to bindings, > you'll need a proxy. You can use #to_activerecord_proxy on the AR > instance, or create it in one go with: > MailboxProxy.create etc. > > You can than add it to the ActiveRecordSetController with > #addObject(proxy). > > Cheers, > Eloy > > On 28 jan 2008, at 20:37, Cory Loken wrote: > >> I am just beginning to explore the ActiveRecord support in RubyCocoa. >> Everything works great when I want to allow everything to be handled >> by AR, but there are a few cases where I would like to manipulate the >> data before the records are created, modified, or destroyed. In one >> case I would like to update a cell if another column in that row is >> modified. I've managed to do this by creating my own >> rbSetValue_forKey >> method and then calling the super method if I don't need to do >> anything special. I am totally lost however on what to do when I want >> to create my own record from values in my script or delete a record >> manually. Is this documented anywhere or does anyone have a >> suggestion >> on how I might do this? >> >> Thanks for any info. >> >> Cory >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Rubycocoa-talk mailing list >> Rub...@li... >> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk Cory |