# Help :: Updateall method

**URL:** <https://www.ruby-forum.com/t/help-updateall-method/93273>\
**Category:** Rails\
**Created:** [April 30, 2007, 11:02am UTC](https://www.ruby-forum.com/t/help-updateall-method/93273 "2007-04-30T11:02:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 11:02am UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/1 "2007-04-30T11:02:07Z")

</div>

Hi all,  
I am unable to write updateall method for my application.  
I want to edit all projects from project table for particular resource  
and update them all at once.

My 2 tables

# Resource

id  
name  
info

# project

id  
title  
type  
resource\_id

My view.rhtml as,

\<% @resource.projects.each do |project| %\>

| **Project Title** | |
| **Project Type** | |

\<% end %\>

I’ve to write controller ,but failed to  
def updateall

end

Please help me out.

Thanks,

---

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 11:17am UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/2 "2007-04-30T11:17:20Z")

</div>

Hi!  
Unless i am missing something you want to make changes and save them  
back. I think you can collect all the ids of the projects using the  
collect  
statement in Ruby and then run a loop if request.post? with these id and  
for  
each textarea you can just use the Modelname.update method.  
Thanks and regards,  
Swanand.

---

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 11:19am UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/3 "2007-04-30T11:19:20Z")

</div>

i meant ids of all the projects for that particular resource.

---

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/4 "2007-04-30T14:13:34Z")

</div>

Hi!  
def yourmethodname  
@all\_project\_id =  
@resource.projects.collect{|single\_project|single\_project.id}  
if request.post?  
for project\_id in @all\_project\_id  
Project.update(project\_id,  
:whatever\_attribute =\> params[: #Give  
the  
name of the textbox with the

project\_id appended to it]  
end  
end  
end  
Hope this helps,

Thanks and regards,  
Swanand

---

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/5 "2007-04-30T15:57:31Z")

</div>

Swanand Deodhar wrote:

> Hi!  
> def yourmethodname  
> @all\_project\_id =  
> @resource.projects.collect{|single\_project|single\_project.id}  
> if request.post?  
> for project\_id in @all\_project\_id

thanks swanand,  
That was good help

Regards,

---

<div class="post-metadata">

**Author:** ![aveo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@aveo](https://www.ruby-forum.com/u/aveo)\
**Post date:** [April 30, 2007, 1:51pm UTC](https://www.ruby-forum.com/t/help-updateall-method/93273/6 "2007-04-30T13:51:15Z")

</div>

Swanand Deodhar wrote:

> i meant ids of all the projects for that particular resource.

Swanand,  
Thanks for your reply. Actually I am new to Ruby and web technologies  
too. So sometime not understand the terms. Ok.  
you mean say, I need to post all my project ids for particular user,  
collect them in controller, But how to update that row. I am unable to  
get Modelname.update term.

Regards,
