On Sep 17, 2:13 am, Eloy Duran <[EMAIL PROTECTED]> wrote:
> >> I'm not particularly attached to using two different faux accessors
> >> for create vs update. It's nice and clean, but really any way that
> >> lets you tell create vs update is fine by me.
>
> I'm sorry, but my English is not good enough to follow this bit.
> Could you maybe explain it some more or in other words?
I think he's referring to Approach 2 (of http://gist.github.com/gists/10793
) which has both a new_task_attributes and existing_task_attributes
accessor. I'm not very fond of this either, especially when you're
setting it directly through Ruby and not using form params.
BTW Eloy, I saw your idea of using the timestamp when adding new task
records (through javascript). Genius!
What if we support both Approach 1 and Approach 4? Here's the logic in
pseudo code.
--
def tasks=(new_tasks)
if new_tasks is a hash
grab values (as array) and sort by keys
call self.tasks= with new values array
else
for each task in new_tasks
if task is hash
if task has id key
update existing task matching id
else
add new task with hash attributes
end
else
add task
end
end
end
end
--
Supporting both hashes and arrays opens up a lot of flexibility.
Generally you'd use an array when dealing directly in Ruby, but a hash
when going through a form.
Regards,
Ryan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---