On Mon, Apr 21, 2008 at 11:18 PM, Adam Meehan <[EMAIL PROTECTED]> wrote:
> I just wanted some feedback on a AR hack I have been playing with
> which implements the block syntax for create and update method.
>
> For example, instead of:
>
> @person = Person.new(params[:person])
> @person.has_rails_patch = false
> @person.set_status :uncool
> @person.save
>
> You could do:
>
> @person = Person.create(params[:person]) do |p|
> p.has_rails_patch = false
> p.set_status(:uncool)
> end
>
> And the update version
>
> @person = Person.update(params[:id], params[:person]) do |p|
> p.set_status(:cool)
> end
>
> It makes it more Rubyish with the blocks, don't you think? The bang!
> versions could added easily enough, for create anyway.
>
> Let me know what you think before I put a patch in.
I like it. Note that new takes a block, so you can already
@person = Person.new(params[:person]) do |p|
p.has_rails_patch = false
p.set_status :halfway
end.save!
if you like.
Best,
jeremy
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---