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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---