[Rails] Re: has a field through an association
On Apr 18, 1:59 pm, Garrett Lancaster <glanc...@garrettlancaster.com>
wrote:
> Hey guys,
>
> Trying to figure out how to do something like the following:
>
> class Child
> belongs_to :parent
> has_field :some_field, :through => :parent
> end
>
> class Parent
> has_one :child
> attr_accessible :some_field
> end
>
> child.some_field #=> parent.some_field
> child.some_field = value #=> sets parent.some_field = value
>
> I can of course accomplish this by adding custom accessors to Child, but
> looking for a better solution. I could also write a plugin that
> dynamically adds the accessors, but not sure if something already exists.
>
It sounds like you're looking for something like delegate_belongs_to:
https://github.com/faber/delegate_belongs_to
It does pretty much exactly what you've described.
--Matt Jones
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home