I have a task model and in the controller there is this code that sets the date a task was completed on if params[:completed] comes back as true and sets the completed_by field to nil (ie incomplete) if params [:completed] comes back as false: @task.completed_on = params[:completed] ? Time.now.to_s(:db) : nil Users can edit the task and this code is in the edit view - allowing the user to tick the box to mark a task as complete or untick it to change the task''s status back to incomplete: <%= check_box_tag :completed, "1", @task.completed_on %> This all works fine. However, if I try to use AJAX to access the update controller directly with the following urls: /tasks/3?completed=true, _method = PUT /tasks/3?completed=false, _method = PUT The first one works, but the second doesn''t reset the completed_by field back to nil. Does anybody know why this isn''t working? I''ve a feeling it might be because ruby is seeing ''false'' as a string and therefore ''true''. cheers, DAZ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Does anybody know why this isn''t working? I''ve a feeling it might be > because ruby is seeing ''false'' as a string and therefore ''true''. >Precisely. all parameters are just strings, it''s up to you to coerce it to a boolean value> cheers, > > DAZ > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply Frederick, I just have two questions: 1) How exactly do I coerce it into a boolean value - is there a best- practice way of doing this? 2) How come this problem doesn''t occur when the value is submitted via the form from the edit action? cheers, DAZ On Dec 13, 5:28 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Does anybody know why this isn''t working? I''ve a feeling it might be > > because ruby is seeing ''false'' as a string and therefore ''true''. > > Precisely. all parameters are just strings, it''s up to you to coerce > it to a boolean value > > > cheers, > > > DAZ--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 13, 7:32 pm, DAZ <daz4...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply Frederick, I just have two questions: > > 1) How exactly do I coerce it into a boolean value - is there a best- > practice way of doing this? >doesn''t need to be any more complicated than if params[:foo] =''true'' ...> 2) How come this problem doesn''t occur when the value is submitted via > the form from the edit action? >if you were just using update_attributes then it understands this sort of stuff IIRC. Fred> cheers, > > DAZ > > On Dec 13, 5:28 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > Does anybody know why this isn''t working? I''ve a feeling it might be > > > because ruby is seeing ''false'' as a string and therefore ''true''. > > > Precisely. all parameters are just strings, it''s up to you to coerce > > it to a boolean value > > > > cheers, > > > > DAZ--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cheers Fred, that worked great! DAZ On Dec 13, 11:12 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 13, 7:32 pm, DAZ <daz4...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply Frederick, I just have two questions: > > > 1) How exactly do I coerce it into a boolean value - is there a best- > > practice way of doing this? > > doesn''t need to be any more complicated than if params[:foo] => ''true'' ...> 2) How come this problem doesn''t occur when the value is submitted via > > the form from the edit action? > > if you were just using update_attributes then it understands this sort > of stuff IIRC. > > Fred > > > cheers, > > > DAZ > > > On Dec 13, 5:28 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > Does anybody know why this isn''t working? I''ve a feeling it might be > > > > because ruby is seeing ''false'' as a string and therefore ''true''. > > > > Precisely. all parameters are just strings, it''s up to you to coerce > > > it to a boolean value > > > > > cheers, > > > > > DAZ--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---