Update a database table without a form

Hi everybody,

a few days ago I began to build a group manager which only use AJAX for
the CRUD - functions. But I have some problems now. The content of the
database table will be editable by cklicking on the name of the group
(see on the attached image). After that the name will be replaced by an
input tag and some buttons will be displayed with different functions.
My problem is that Rails need the ID of this table row for the form to
submit the data to my update - method. Is there a way to update the data
without a form?

Eddy

I’m not 100% sure what exactly you want to do :slight_smile:

But of course you can send technically whatever you want to rails as a
param in a call with link_to, link_to_remote, remote_function or
whatever function that establishes a connection browser/server

In most cases you will only send an id and the necessary data to update
it.

link_to “update something”, something_path(foo.id, :something_more =>
“new text”)
is the most primitive way

If you want to “simulate” form behavior, to reuse the update controller
you use anyway, the only important thing is the naming of the params.
If you look at the generated html for a form, you’ll notice that field
naming follows the convention name=“model[method]”

so if you have a User form and a name field
link_to “update user”, user_path(user.id, “user[name]” => “new name”)
could be sent and would be accessible as
params[:user][:name] as usual

Thorsten M. wrote:

I’m not 100% sure what exactly you want to do :slight_smile:

But of course you can send technically whatever you want to rails as a
param in a call with link_to, link_to_remote, remote_function or
whatever function that establishes a connection browser/server

In most cases you will only send an id and the necessary data to update
it.

link_to “update something”, something_path(foo.id, :something_more =>
“new text”)
is the most primitive way

If you want to “simulate” form behavior, to reuse the update controller
you use anyway, the only important thing is the naming of the params.
If you look at the generated html for a form, you’ll notice that field
naming follows the convention name=“model[method]”

so if you have a User form and a name field
link_to “update user”, user_path(user.id, “user[name]” => “new name”)
could be sent and would be accessible as
params[:user][:name] as usual

I solve the problem with a little javascript which manipulate the action
attribute of my form and it update my data like a champ :wink:

Thanks Thorsten for your help!