# Rendering data in tables

**URL:** <https://www.ruby-forum.com/t/rendering-data-in-tables/137928>\
**Category:** Rails\
**Created:** [May 18, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/rendering-data-in-tables/137928 "2008-05-18T14:20:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@sai](https://www.ruby-forum.com/u/sai)\
**Post date:** [May 18, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/rendering-data-in-tables/137928/1 "2008-05-18T14:20:14Z")

</div>

Hello all,

I am new to Rails.  
I don’t know whether it is possible are not.

In my application, I need get data from one table , then arrange these  
data in table in textfield, then I need to edit data in all rows in  
single form.

At the end I need to save these data back to databse.

How can I do this

Is this possible

\<%= tag(“input” , {:type =\> ‘’, :id=\>"\<%= %\> " … %\>

Thanks in advance

---

<div class="post-metadata">

**Author:** ![sai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@sai](https://www.ruby-forum.com/u/sai)\
**Post date:** [May 19, 2008, 9:32am UTC](https://www.ruby-forum.com/t/rendering-data-in-tables/137928/2 "2008-05-19T09:32:00Z")

</div>

1 Table or 1 Record only? if in 1 table it means that  
ModelName.find(:all)  
Both 1 table or 1 record from ActiveRecord action can be saved in 1  
field or column as textfield. If you call data from table it will be  
provided in array unless you call data only sigle record like  
ModelName.find(id), it would be hash form. If array is saved to a column  
of a table. The array would be formed as YAML.

sai wrote:

> In my application, I need get data from one table , then arrange these  
> data in table in textfield, then I need to edit data in all rows in  
> single form.  
> At the end I need to save these data back to databse.
> 
> How can I do this
> 
> Is this possible

Yes you can do it.

@test = Employee.find(:all)

#it will save all data of table Employee  
#in only 1 column as text field in ImportEmployee Table.

@other = ImportEmployee.new  
@other.old\_employee = @test  
@other.save!

#to call back data and edit it then save it to Employee.  
#you can use it

@other = ImportEmployee.find(params[:id])

@employees = YAML.load(@other.old\_employee)

# in your view to edit

\<% form\_tag :action =\> ‘your\_method’ do %\>

\<% for employ in @employees %\>

\<%= text\_field ‘employee[id][]’, :value=\> employ.id %\>  
\<%= text\_field ‘employee[column\_1][]’, :value=\> employ.column\_1 %\>  
.  
.  
.  
\<% end %\> \<%#–end for— %\>  
\<% end %\> \<%#–end form— %\>

Then in your controller

def your\_method

for param in params[:employee]  
@save\_employee = Employee.find(param[:id])  
@save\_employee.update\_attributes(param)  
end

#maybe when you run my code, it would be error, because i not try it  
#but the algo is closed like that, we can try by doing.

> \<%= tag(“input” , {:type =\> ‘’, :id=\>"\<%= %\> " … %\>

Dont use double \<%= %\>,it will be error.

> Thanks in advance

You’re Welcome.

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![sai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@sai](https://www.ruby-forum.com/u/sai)\
**Post date:** [May 19, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/rendering-data-in-tables/137928/3 "2008-05-19T16:36:43Z")

</div>

> In my application, I need get data from one table , then arrange these  
> data in table in textfield, then I need to edit data in all rows in  
> single form.
> 
> At the end I need to save these data back to databse.

Have a look at this plugin:

[http://os.flvorful.com/super\_in\_place\_controls](http://os.flvorful.com/super_in_place_controls)

If you’re looking for a spreadsheet-like appearance where you have all  
fields as inputs right away, and the database is updated instantly  
(onchange) without an OK button, it’s not exactly that. But maybe it’s  
customizable, I haven’t really looked into it.

> Is this possible
> 
> \<%= tag(“input” , {:type =\> ‘’, :id=\>"\<%= %\> " … %\>

You can’t wrap a \<%= %\> inside another. What are you trying to do? If  
you  
want to calculate the value for id, just omit the quotes:

\<%= … , :id =\> some+ruby.expression, … %\>
