I’m trying to duplicate a resource in Rails in my application and was running into some issues.
The setup is: I have a library of ‘item templates’ that the user can use, then modify the resulting item. I currently have a setup like this:
@temp_item = @template_item.dup
@new_item = @user.items.create(@temp_item.attributes)
However I’m running into a problem where it’s trying to copy across protected attributes as well (namely created_at and updated_at). I’d rather not list out each attribute individually, so my question is, is there a way to exclude attributes being copied in this instance?
Thanks.
Incorporating Mischa’s good suggestion into my original answer.