From: Cory L. <co...@ma...> - 2008-01-29 20:17:12
|
Thanks for the input. Things are starting to make sense. I'm still a bit lost on the new record thing. I think my confusion is when it comes to the bindings/outlets. I've done the following as suggested: class MyController < OSX::NSObject ib_outlet :record_set_controller def some_action # add a new record, with proxy, to the managed content of the ActiveRecordSetController @record_set_controller.addObject MyClassProxy.create end end some_action is triggered when enter is pressed in a text field. In IB I've added a key to MyClassProxy for record_set_controller (and several variations similar), but I continue to get this error: MyController#rbValueForKey: OSX::OCMessageSendException: Can't get Objective-C method signature for selector 'create' of receiver MyClassProxy. I feel like I'm on the verge of getting this, but staring at the screen with the same results for the past few hours is getting me no where. Would you happen to know if there is an example that might help explain this process? I think the issue is stemming from MyController not being able to properly access MyClass or MyClassProxy as any attempt to even use methods in those classes results in a similar error. Thanks again for your help so far. Cory On Jan 29, 2008, at 1:20 AM, Eloy Duran wrote: > Ah ok, I thought you wanted to update a NSTableColumn. > > If you just want to deal with ActiveRecord data, you should only deal > with > that in your model, so in your case MyClass something like: > > class MyClass < ActiveRecord::Base > before_update :update_price > > def update_price > self.price = 342 > end > end > > The proxies are just a very thin layer between the model and bindings. > So all your data stuff goes into to the model and if you need to do > some > special work on your data when it goes from the model to the bindings > or vice vers > then you do that in the proxy. > > When you create a new record and a proxy for it you still need to add > it to the collection that's > being managed by the ActiveRecordSetController. The > ActiveRecordSetController is a > subclass of NSArrayController, so you can check the docs for that on > adding objects to the collection: > http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSArrayController_Class/Reference/Reference.html > > If you want to do this you'll need a reference (IB outlet) to the > ActiveRecordSetController in your controller. > You can then do something like: > > class MyController < OSX::NSObject > ib_outlet :record_set_controller > > def some_action(sender) > # add a new record, with proxy, to the managed content of the > ActiveRecordSetController > @record_set_controller.addObject MyClassProxy.create > end > end > > Cheers, > Eloy > > On 29 jan 2008, at 01:32, Cory Loken wrote: > >> 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 >> >> >> ------------------------------------------------------------------------- >> 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 |