problem in _todo partial
|
|
hi, its a rather particular circumstance… but if I 1. add a task I get this error: ActionView::TemplateError (Called id for nil, which would mistakenly be 4—if you really wanted the id of nil, use object_id) on line #3 of app/views/today/_todo.rhtml: 1: <l id="todo_" i><= todo.id %>”> |
|
|
Is your Task model using the version from the book or the correct one from the source / errata (see http://www.railsprojects.com/forums/3/topics/17)? If it’s missing the :dependent => :destroy option that would cause that. |
|
|
my Task model has the line: has_one :todo, :dependent => :destroy Which i saw in the errata. has_one :todo, :dependent => true |
|
|
both work in the 1.2 version of rails (don’t think they do in 2.0) – however the :dependent => :destroy became the preferred approach. I think it’s because it also allows you a little more flexibilty. i.e. you can also set it to :dependent => :nullify to remove the foreign_id yet keep the record. |
|
|
Actually just went back and tested your report and you’re right there is a bug there. In my haste I didn’t notice that by scoping the delete it wasn’t really deleting the todo but merely nullifying the schedule_id from that todo. In all actuality there is no need to scope that search (i.e. making sure it’s associated with the current users schedule ) for the todo object twice. Changing the delete method in the todo controller to this – should fix this bug def destroy
todo = current_user.schedule.todos.find(params[:id])
Todo.delete(todo)
redirect_to(:controller => "today", :action => "index")
end
I’ve updated the errata here on the site. Thanks for catching this!! |