# Different views/same action

**URL:** <https://www.ruby-forum.com/t/different-views-same-action/130749>\
**Category:** Rails\
**Created:** [March 3, 2008, 1:05am UTC](https://www.ruby-forum.com/t/different-views-same-action/130749 "2008-03-03T01:05:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [March 3, 2008, 1:05am UTC](https://www.ruby-forum.com/t/different-views-same-action/130749/1 "2008-03-03T01:05:20Z")

</div>

Good evening all.

I have two different places in my app that need to call the same  
controller/action and react differently in terms of output. In other  
words, in one case I want to use some rjs to update a page in a certain  
way and in another case - I’d like to to do something entirely different  
to a different/distinct page but use the same controller/action.

Say controller is foo and action is ‘unsubscribe’…

class Foo \<\< ApplicationController  
def unsubscribe  
foo = SomeModel.find(params[:id])  
if foo  
SomeModel.delete\_all(:condtions…)  
end

```
# in one case i want to update the calling page (x) with some

```

indication  
# in another, the page has a completely different dom and i need to  
do something else  
render :update do |page|  
page.do\_something  
end  
end  
end

Is the answer to just create two actions here?

---

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [March 3, 2008, 4:05am UTC](https://www.ruby-forum.com/t/different-views-same-action/130749/2 "2008-03-03T04:05:24Z")

</div>

Cory W. wrote:

> Is the answer to just create two actions here?  
> It’s not the only answer but I prefer it over the alternative which is  
> to pass a hidden field into the controller indicating which branch it is  
> to follow.

Of course splitting your code into more methods leads to more  
maintainable, easier to understand, more cohesional, prettier, and  
easier test case coverage goodness but who cares about those things  
anyways… 🙂

If your action names are starting to match in the controller space then  
maybe it’s time you split into another controller…

---

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [March 3, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/different-views-same-action/130749/3 "2008-03-03T19:09:49Z")

</div>

@Cory, take a look at the RJS proxies for the DOM. Things like  
page.select(…).any should help for what you’re trying to achieve.

On Mar 2, 7:05 pm, Cory W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
