Yes. Override otherfield= on your model class to set decide_id and detail_id
class MyModel < ActiveRecord::Base
def otherfield=(value)
device_id = otherfield
detail_id = otherfield + "action"
#write_attribute "otherfield", value
end
If otherfield is meaningful in your database then you''re going to want
to uncomment that last line too, otherwise otherfield won''t actually
get set at the model. If it''s just used to generate the other two then
that''s unneccesary. I''m assuming you''re passing
@params[''my_model''] or
equivalent directly into create and update (which will cause
otherfield= to get called if otherfield shows up in the params hash).
Brian
On Fri, 4 Feb 2005 16:08:48 -0900, Mike Barsalou
<mbarsalou-j70nRCKfdoj9MGWgvH5pYw@public.gmane.org>
wrote:> I have an application who''s table looks like this
>
> id
> device_id
> detail_id
> otherfield
> description
>
> Is it possible when creating a new record that I can have device_id and
> detail_id filled with data that was typed in on the form from otherfield?
>
> Or even some calculated value?
>
> How would I make the end result record to look like this:
>
> device_id = otherfield
> detail_id = otherfield + "action"
>
> I''ve been using the documentation, but often I am not sure where
the code is
> supposed to go....I have been assuming it would only go in the
"controller".
> How do I decide?
>
> Thanks
>
> Mike B.
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
The years ahead pick up their dark bags.
They move closer. There''s a slight rise in the silence
then nothing.
--
(If you''re receiving this in response to mail sent to
bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned
This is my new address,
but mail will be forwarded here indefinitely)