Update database-field with prototype

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

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

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 C. [email protected]

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

thanks fred. works like a charm.
and it all sounds logical now that you’ve said it :slight_smile:

On May 20, 4:04 pm, Frederick C. [email protected]

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”