# Replacing table row with form

**URL:** <https://www.ruby-forum.com/t/replacing-table-row-with-form/157118>\
**Category:** Rails\
**Created:** [January 7, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/replacing-table-row-with-form/157118 "2009-01-07T14:44:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [January 7, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/replacing-table-row-with-form/157118/1 "2009-01-07T14:44:56Z")

</div>

I need a way to replace a table row with a form to edit it’s values –  
kind of like edit-in-place, only that I need a custom form (check boxes,  
select lists, text fields, etc). My table is generated with a partial of  
a model.

The row should have a button/link to enable to go in and out of edit  
mode, and this should be done asynchronously. Here’s what I came up with  
so far:

# view

 \<%= render :partial =\> 'person', :collection =\> @people %\> 

# partial

\<% @person = person -%\>  
\<% @row\_id = “person\_#{person.id}” %\>

 \<%= link\_to\_remote 'edit', :url =\> { :action =\> 'edit\_row'} %\> \<%= person.name %\> \<%= person.age %\>

I need help with the controller and how to replace the specific row  
(with id=“person\_”) with a form. Should the form be hidden in the  
partial and controlled by a boolean passed to it (if true, show form \>  
else show the normal view)? meaning:

\<% if edit\_mode -%\>  
\<% form\_for :person do |f| -%\>

\<%= f.text\_field :name %\>  
\<%= f.text\_field :age %\>  
\<%= f.submit ‘go’ %\>  
\<% end -%\>  
\<% else -%\> \<%= link\_to\_remote 'edit', :url =\> { :action =\> 'edit\_row'} %\> \<%= person.name %\> \<%= person.age %\> \<% end -%\>

I can’t be the only one who’s trying to do this, so I’d really  
appreciate any thoughts, insights and such. Thanks in advance!
