Trevor Turk
2008-May-23 21:12 UTC
Not able to use block-setting of attributes via association
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/tickets/248-not-able-to-use-block-setting-of-attributes-via-association
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---
Trevor Turk
2008-May-23 21:20 UTC
Re: Not able to use block-setting of attributes via association
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/tickets/248-not-able-to-...Note that one workaround seems to be: User.last.posts.new(:title => ''my post'') { |p| p.body = "body" }.save - Trevor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bates
2008-May-23 22:02 UTC
Re: Not able to use block-setting of attributes via association
I added a patch to the ticket. Both "create" and "create!" are supported. Ryan On May 23, 2:20 pm, Trevor Turk <trevort...@gmail.com> wrote:> 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/tickets/248-not-able-to-... > > Note that one workaround seems to be: > > User.last.posts.new(:title => ''my post'') { |p| p.body = "body" }.save > > - Trevor--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---