Active record statement invalid

Subscribe to Active record statement invalid 6 post(s), 2 voice(s)

 
Avatar SashaSki 4 post(s)

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
: UPDATE schedules_todos SET position = 1 WHERE schedule_id = 1 AND todo_id =

The App Trace says the error is in app/controllers/todo_controller.rb:6
That line is: current_user.schedule.todos.create(:task_id => task.id)

I’ve gone through the source code and can’t see what the problem is, any help would be great!

 
Avatar EldonAlameda Administrator 216 post(s)

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

 
Avatar SashaSki 4 post(s)

Thanks for taking the time, ive uploaded it here: http://goodphoto-greatphoto.co.uk/sasha/monkeytasks.zip

 
Avatar EldonAlameda Administrator 216 post(s)

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 => :schedule 
as 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>

 
Avatar SashaSki 4 post(s)

Thank you very much I see where I went wrong now, everything is working great now!

 
Avatar EldonAlameda Administrator 216 post(s)

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. :-)