Forum: Rails-core (closed, excessive spam) Not able to use block-setting of attributes via association

Posted by Trevor Turk (Guest)
on 2008-05-23 23:12
(Received via mailing list)
I just created a ticket for this issue, but I thought it worth
bringing it up here as well:

http://rails.lighthouseapp.com/projects/8994/ticke...

The issue is that you can't set attributes with a block if you do so
through an association. So, while the following would set the body of
the Post to "body":

Post.create(:title => 'my post') { |p| p.body = "body" }

...this would not:

User.last.posts.create(:title => 'my post') { |p| p.body = "body" }

This ticket could be viewed as an enhancement request, of course, but
it seemed like something worth having in 2.1 to me.

My apologies, but I don't have the necessary Rails-internals-fu to add
a proper patch with a fix myself.

Thanks,
- Trevor
Posted by Trevor Turk (Guest)
on 2008-05-23 23:21
(Received via mailing list)
On May 23, 4:12 pm, Trevor Turk <trevort...@gmail.com> wrote:
> I just created a ticket for this issue, but I thought it worth
> bringing it up here as well:
>
> http://rails.lighthouseapp.com/projects/8994/ticke......

Note that one workaround seems to be:

User.last.posts.new(:title => 'my post') { |p| p.body = "body" }.save

- Trevor
Posted by Ryan Bates (Guest)
on 2008-05-24 00:03
(Received via mailing list)
I added a patch to the ticket. Both "create" and "create!" are
supported.

Ryan
This topic is locked and can not be replied to.