hi guys, i am trying to update a database-field with the help of prototype. there is something i must have missed because i tried every single combination but the only stuff that worked was GETing a field out of the db and creating a new one without content. i thought that calling remotes/1 with PUT would update my db field (remote is the name of my controller). so i did something like this: function update_db(){ var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'', { method: ''put'', parameters: ''1'', asynchronous: true, postBody: ''hello'' }); } but this just creates a new, empty record. when i add the "1" to the url and remove the parameters it says "no action responding to 1". i would be really grateful if someone could help me with this. (btw i am calling the method update_db via the firebug console, if this is of any interest) regards, chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 May 2008, at 14:34, Chris-Aix wrote:> > hi guys, > > i am trying to update a database-field with the help of prototype. > there is something i must have missed because i tried every single > combination but the only stuff that worked was GETing a field out of > the db and creating a new one without content.What is the action in your controller that handles this? What parameters is it expecting? You need to make sure that lines up with the parameters you''re submiting over ajax (which right now it doesn''t - apart from anything else your postBody isn''t in the format that rails will be expecting. Fred> > > i thought that calling remotes/1 with PUT would update my db field > (remote is the name of my controller). > so i did something like this: > function update_db(){ > var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'', > { > method: ''put'', > parameters: ''1'', > asynchronous: true, > postBody: ''hello'' > }); > } > > but this just creates a new, empty record. when i add the "1" to the > url and remove the parameters it says "no action responding to 1". > i would be really grateful if someone could help me with this. > > (btw i am calling the method update_db via the firebug console, if > this is of any interest) > > regards, > chris > >--~--~---------~--~----~------------~-------~--~----~ 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 your quick answer fred. here is the controller for it. i created this as a web service with scaffolding. # PUT /remotes/1 # PUT /remotes/1.xml def update @remote = Remote.find(params[:id]) respond_to do |format| if @remote.update_attributes(params[:remote]) flash[:notice] = ''Remote was successfully updated.'' format.html { redirect_to(@remote) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @remote.errors, :status => :unprocessable_entity } end end end On May 20, 3:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 May 2008, at 14:34, Chris-Aix wrote: > > > > > hi guys, > > > i am trying to update a database-field with the help of prototype. > > there is something i must have missed because i tried every single > > combination but the only stuff that worked was GETing a field out of > > the db and creating a new one without content. > > What is the action in your controller that handles this? What > parameters is it expecting? > You need to make sure that lines up with the parameters you''re > submiting over ajax (which right now it doesn''t - apart from anything > else your postBody isn''t in the format that rails will be expecting. > > Fred > > > > > i thought that calling remotes/1 with PUT would update my db field > > (remote is the name of my controller). > > so i did something like this: > > function update_db(){ > > var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'', > > { > > method: ''put'', > > parameters: ''1'', > > asynchronous: true, > > postBody: ''hello'' > > }); > > } > > > but this just creates a new, empty record. when i add the "1" to the > > url and remove the parameters it says "no action responding to 1". > > i would be really grateful if someone could help me with this. > > > (btw i am calling the method update_db via the firebug console, if > > this is of any interest) > > > regards, > > chris--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
unfortunately mailing lists are not editable, so sorry for this second mail but i forgot to say that the remotes table consists only of one field: "current" On May 20, 3:44 pm, Chris-Aix <OneDay...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> thanks for your quick answer fred. > > here is the controller for it. i created this as a web service with > scaffolding. > > # PUT /remotes/1 > # PUT /remotes/1.xml > def update > @remote = Remote.find(params[:id]) > > respond_to do |format| > if @remote.update_attributes(params[:remote]) > flash[:notice] = ''Remote was successfully updated.'' > format.html { redirect_to(@remote) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @remote.errors, :status > => :unprocessable_entity } > end > end > end > > On May 20, 3:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 20 May 2008, at 14:34, Chris-Aix wrote: > > > > hi guys, > > > > i am trying to update a database-field with the help of prototype. > > > there is something i must have missed because i tried every single > > > combination but the only stuff that worked was GETing a field out of > > > the db and creating a new one without content. > > > What is the action in your controller that handles this? What > > parameters is it expecting? > > You need to make sure that lines up with the parameters you''re > > submiting over ajax (which right now it doesn''t - apart from anything > > else your postBody isn''t in the format that rails will be expecting. > > > Fred > > > > i thought that calling remotes/1 with PUT would update my db field > > > (remote is the name of my controller). > > > so i did something like this: > > > function update_db(){ > > > var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'', > > > { > > > method: ''put'', > > > parameters: ''1'', > > > asynchronous: true, > > > postBody: ''hello'' > > > }); > > > } > > > > but this just creates a new, empty record. when i add the "1" to the > > > url and remove the parameters it says "no action responding to 1". > > > i would be really grateful if someone could help me with this. > > > > (btw i am calling the method update_db via the firebug console, if > > > this is of any interest) > > > > regards, > > > chris--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 May 2008, at 14:44, Chris-Aix wrote:> > thanks for your quick answer fred. > > here is the controller for it. i created this as a web service with > scaffolding. >You''ve got to be giving rails parameters that will understand as a hash with a key ''remote'' containing the right values new Ajax.Request(''/remotes/1'', { method: ''put'', parameters: {''remote[current]'': ''hello world''}, asynchronous: true}) You could have worked out that the secret sauce was remote[current] by looking at the form input names rails generates when you create a regular form. Fred> # PUT /remotes/1 > # PUT /remotes/1.xml > def update > @remote = Remote.find(params[:id]) > > respond_to do |format| > if @remote.update_attributes(params[:remote]) > flash[:notice] = ''Remote was successfully updated.'' > format.html { redirect_to(@remote) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @remote.errors, :status > => :unprocessable_entity } > end > end > end > > On May 20, 3:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 20 May 2008, at 14:34, Chris-Aix wrote: >> >> >> >>> hi guys, >> >>> i am trying to update a database-field with the help of prototype. >>> there is something i must have missed because i tried every single >>> combination but the only stuff that worked was GETing a field out of >>> the db and creating a new one without content. >> >> What is the action in your controller that handles this? What >> parameters is it expecting? >> You need to make sure that lines up with the parameters you''re >> submiting over ajax (which right now it doesn''t - apart from anything >> else your postBody isn''t in the format that rails will be expecting. >> >> Fred >> >> >> >>> i thought that calling remotes/1 with PUT would update my db field >>> (remote is the name of my controller). >>> so i did something like this: >>> function update_db(){ >>> var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'' >>> , >>> { >>> method: ''put'', >>> parameters: ''1'', >>> asynchronous: true, >>> postBody: ''hello'' >>> }); >>> } >> >>> but this just creates a new, empty record. when i add the "1" to the >>> url and remove the parameters it says "no action responding to 1". >>> i would be really grateful if someone could help me with this. >> >>> (btw i am calling the method update_db via the firebug console, if >>> this is of any interest) >> >>> regards, >>> chris > >--~--~---------~--~----~------------~-------~--~----~ 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 fred. works like a charm. and it all sounds logical now that you''ve said it :-) On May 20, 4:04 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 May 2008, at 14:44, Chris-Aix wrote: > > > > > thanks for your quick answer fred. > > > here is the controller for it. i created this as a web service with > > scaffolding. > > You''ve got to be giving rails parameters that will understand as a > hash with a key ''remote'' containing the right values > > new Ajax.Request(''/remotes/1'', { > method: ''put'', > parameters: {''remote[current]'': ''hello world''}, > asynchronous: true}) > You could have worked out that the secret sauce was remote[current] by > looking at the form input names rails generates when you create a > regular form. > > Fred > > > # PUT /remotes/1 > > # PUT /remotes/1.xml > > def update > > @remote = Remote.find(params[:id]) > > > respond_to do |format| > > if @remote.update_attributes(params[:remote]) > > flash[:notice] = ''Remote was successfully updated.'' > > format.html { redirect_to(@remote) } > > format.xml { head :ok } > > else > > format.html { render :action => "edit" } > > format.xml { render :xml => @remote.errors, :status > > => :unprocessable_entity } > > end > > end > > end > > > On May 20, 3:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 20 May 2008, at 14:34, Chris-Aix wrote: > > >>> hi guys, > > >>> i am trying to update a database-field with the help of prototype. > >>> there is something i must have missed because i tried every single > >>> combination but the only stuff that worked was GETing a field out of > >>> the db and creating a new one without content. > > >> What is the action in your controller that handles this? What > >> parameters is it expecting? > >> You need to make sure that lines up with the parameters you''re > >> submiting over ajax (which right now it doesn''t - apart from anything > >> else your postBody isn''t in the format that rails will be expecting. > > >> Fred > > >>> i thought that calling remotes/1 with PUT would update my db field > >>> (remote is the name of my controller). > >>> so i did something like this: > >>> function update_db(){ > >>> var ajaxRequest = new Ajax.Request(''http://localhost:3000/remotes'' > >>> , > >>> { > >>> method: ''put'', > >>> parameters: ''1'', > >>> asynchronous: true, > >>> postBody: ''hello'' > >>> }); > >>> } > > >>> but this just creates a new, empty record. when i add the "1" to the > >>> url and remove the parameters it says "no action responding to 1". > >>> i would be really grateful if someone could help me with this. > > >>> (btw i am calling the method update_db via the firebug console, if > >>> this is of any interest) > > >>> regards, > >>> chris--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---