Active record statement invalid
|
|
Whenever I click on an arrow to place a task into my “Today’s Tasks” I receive the following error: ActiveRecord::StatementInvalid in TodoController#create PGError: ERROR: syntax error at end of input at character 77 The App Trace says the error is in app/controllers/todo_controller.rb:6 I’ve gone through the source code and can’t see what the problem is, any help would be great! |
|
|
Hi, That is an error I haven’t seen before. Could you shoot me a zipped up copy of your application code as it is now and I’ll do a little local testing to see if i can locate the problem. Thanks |
|
|
Thanks for taking the time, ive uploaded it here: http://goodphoto-greatphoto.co.uk/sasha/monkeytasks.zip |
|
|
Okay – found a couple problems in the code. 1. You added some plugin named acts_as_habtm_list in addition to the acts_as_list plugin. (acts_as_list used to be part of Rails core but was moved to a plugin in Rails 2.0). Then in your todo model you were using this acts_as_habtm_list instead: acts_as_habtm_list :scope => :schedule I changed it to acts_as_list :scope => :scheduleas it is in the book to get past this error. However in my testing of moving tasks to and from the current todo list – I noticed that adding more than one task caused the list to have duplicate entries. Looking at your template I noticed this
<ul id="todo-list">
<% for todo in @todos %>
<%= render :partial => 'todo', :collection => @todos %>
<% end %>
</ul>
If you notice – you’re iterating over the collection of todo’s and then calling the partial on the full collection each time (so in essense you’re iterating over them twice) I changed it to this and everything seemed to be working fine afterwards
<ul id="todo-list">
<%= render :partial => 'todo', :collection => @todos %>
</ul>
|
|
|
Thank you very much I see where I went wrong now, everything is working great now! |
|
|
Groovy. Glad I was able to solve it for you : that other plugin really through for a loop until I noticed that it was installed. Then it suddenly made sense why Rails was looking a join table that didn’t exist. :-) |