# Update a database table without a form

**URL:** <https://www.ruby-forum.com/t/update-a-database-table-without-a-form/139630>\
**Category:** Rails\
**Created:** [June 5, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/update-a-database-table-without-a-form/139630 "2008-06-05T17:32:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddy\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@eddy\_b](https://www.ruby-forum.com/u/eddy_b)\
**Post date:** [June 5, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/update-a-database-table-without-a-form/139630/1 "2008-06-05T17:32:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eddy\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@eddy\_b](https://www.ruby-forum.com/u/eddy_b)\
**Post date:** [June 5, 2008, 5:47pm UTC](https://www.ruby-forum.com/t/update-a-database-table-without-a-form/139630/2 "2008-06-05T17:47:04Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![eddy\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@eddy\_b](https://www.ruby-forum.com/u/eddy_b)\
**Post date:** [June 5, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/update-a-database-table-without-a-form/139630/3 "2008-06-05T18:06:42Z")

</div>

Thorsten M. wrote:

> I’m not 100% sure what exactly you want to do 🙂
> 
> 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 😉

Thanks Thorsten for your help!
