Hi All, As part of a wider application, I have a todo list set up with boolean column indicating if the todo is complete or not. It defaults to false to indicate not complete. I''m using a check box that calls a defined action called complete_item. At the moment it looks like this: class TodosController < ApplicationController ... def complete_item @todo = @matter.todos.find_by_id(params[:id]) @todo.complete = true @todo.save ... end I have also tried the following various methods, none of which work: @todo.update_attributes(:complete, true) @todo.attributes(:complete)=true @todo.complete=true I''ve also tried replacing true with 1. I can see from the logs that the object is being updated but with the complete field still set to false. Any thoughts? Thanks Robin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
can you give more details like, what database are you using. MySql, sqlite ?? what does your Todo model class look like? callbacks? validations? On 19 feb, 19:42, Robin Fisher <robinjfis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > As part of a wider application, I have a todo list set up with boolean > column indicating if the todo is complete or not. It defaults to > false to indicate not complete. > > I''m using a check box that calls a defined action called > complete_item. At the moment it looks like this: > > class TodosController < ApplicationController > ... > def complete_item > @todo = @matter.todos.find_by_id(params[:id]) > @todo.complete = true > @todo.save > ... > end > > I have also tried the following various methods, none of which work: > > @todo.update_attributes(:complete, true) > @todo.attributes(:complete)=true > @todo.complete=true > > I''ve also tried replacing true with 1. > > I can see from the logs that the object is being updated but with the > complete field still set to false. Any thoughts? > > Thanks > > Robin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
My sense is that maximilianog is on the right track. Often when debugging an issue like this I''ll add something like this: @todo.errors.each{|attr, errs| logger.debug "#{attr.to_s.humanize} #{errs.to_s}" } unless @todo.valid? The log messages (or their absence) will help you understand if your failure to update is related to validations. How are you defaulting complete to false? Is it the default value (db) or via code? @todo.update_attributes(:complete, true) ^ This one doesn''t work because update_attributes (plural) takes a hash. Make it singular (update_attribute) and you might have success. On Feb 19, 8:08 pm, maximilianog <maximiliano.guz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> can you give more details like, what database are you using. MySql, > sqlite ?? what does your Todo model class look like? callbacks? > validations? > > On 19 feb, 19:42, Robin Fisher <robinjfis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi All, > > > As part of a wider application, I have a todo list set up with boolean > > column indicating if the todo is complete or not. It defaults to > > false to indicate not complete. > > > I''m using a check box that calls a defined action called > > complete_item. At the moment it looks like this: > > > class TodosController < ApplicationController > > ... > > def complete_item > > @todo = @matter.todos.find_by_id(params[:id]) > > @todo.complete = true > > @todo.save > > ... > > end > > > I have also tried the following various methods, none of which work: > > > @todo.update_attributes(:complete, true) > > @todo.attributes(:complete)=true > > @todo.complete=true > > > I''ve also tried replacing true with 1. > > > I can see from the logs that the object is being updated but with the > > complete field still set to false. Any thoughts? > > > Thanks > > > Robin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---