Taking this article as a starting point:
Rails Way Blog - Association Proxies
and looking specifically at
def create
@todo_list = current_user.todo_lists.build params[:todo_list]
if @todo_list.save
redirect_to todo_list_url(@todo_list)
else
render :action=>'new'
end
end
This is a way of making sure you assign ownership to the user
BUT supposing the ToDo list was a many-many relationship associated in a has_many through i.e.
def User < AR:Base
has_many :user_todos
has_many :todo_lists, :through => :user_todos
end
At this point...
@todo_list = current_user.todo_lists.build params[:todo_list]
still works but only the todo_list is saved and not the join. How can I get the joy of association proxies without having lots of nested if/else should the join or Todo instance not validate when saved.
I was thinking of something along the lines of...
@todo_list = cu.user_todos.build.build_to_do(params[:todo_list])
but as I mentioned above the user_todos don't get saved.
Your help is greatly appreciated!
Kevin.