Different views/same action

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?

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… :slight_smile:

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

@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. [email protected]