On Jul 26, 2011, at 2:28 PM, kevinpfromnm wrote: > I'm wondering if anyone has done or knows of a simple way to implement an > attr_accessor that behaves like a belongs_to association. I'm making a > lifecycle transition and need to pass a parameter that is an id to another > model and thought if I could define it with a type like an association, I > could get the desired behavior without having to touch the view.
I've used the :params => :some_belongs_to_association trick before in transitions (very slick) but not with a virtual attribute. Here's a first swipe at what should work: (in the model): attr_accessor :some_field_name, :type => ModelClass def some_field_name=(v) @some_field_name = v.is_a?(ModelClass) ? v : ModelClass.find(v) end Declare an input for ModelClass that makes a dropdown list - select-one *may* do the right thing here, but you'll have to pass an explicit list of options to it or it'll blow up trying to do a reflection. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
