# Multiple Update Actions that are Relatively the same

**URL:** <https://www.ruby-forum.com/t/multiple-update-actions-that-are-relatively-the-same/103268>\
**Category:** Rails\
**Created:** [May 3, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/multiple-update-actions-that-are-relatively-the-same/103268 "2007-05-03T16:52:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [May 3, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/multiple-update-actions-that-are-relatively-the-same/103268/1 "2007-05-03T16:52:47Z")

</div>

Hi there,

I have 2 actions that are rather identical:

# Put /account/you/update\_password

def update\_password  
@user = current :user  
respond\_to do |format|  
if @user.update\_attributes(params[:user])  
format.html {redirect\_to account\_url}  
else  
format.html {render :action =\> “edit\_password”}  
end  
end  
end

# PUT /account/you

# Update the user object.

def update  
@user = current :user  
respond\_to do |format|  
if @user.update\_attributes(params[:user])  
format.html {redirect\_to account\_url}  
else  
format.html {render :action =\> “edit”}  
end  
end  
end

The only thing that differs between the 2 is in the “else” part {render  
:action =\> “edit” or render :action =\> “edit\_password”} lines. In the  
past  
when I have encountered a situation like this I’d use one action, and in  
the  
forms I’d stick an extra param indicating what action to render if an  
error  
occurred. Doing that seemed kind of clunky in my opinion.

This seems like something common, and/or simple that I’m just  
overlooking.  
Is going with the extra param in the form the best route?

Thanks,  
Dave

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [May 3, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/multiple-update-actions-that-are-relatively-the-same/103268/2 "2007-05-03T17:54:59Z")

</div>

I do not know if having 2 methods is best, but to reduce the  
duplication you could always create a utility method that does all the  
common part and takes a block for the unique part, then evaluates the  
block in the else clause.

Michael

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [May 3, 2007, 6:08pm UTC](https://www.ruby-forum.com/t/multiple-update-actions-that-are-relatively-the-same/103268/3 "2007-05-03T18:08:00Z")

</div>

Sounds like a good idea. I was considering something like that. I think  
that  
might be the best route.

-Dave
