Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I call an action in another action (in a rails controller)?

When an action in a controller has been called, can I then call another action from that action?

And what would happen if both actions have some template to render?

like image 948
Bat Avatar asked Apr 26 '10 01:04

Bat


Video Answer


1 Answers

Yes you can, if it is in the same controller.

Calling zoo will provide the template for zoo with instances for @x and @a. Neither foo or bar will be rendered. If you have explicitly set a render method, then you might get a double render error, unless you return before the second render is called.

def foo
  @x = 1
end

def bar
  @a = 2
end

def zoo
  foo
  bar
end
like image 98
The Who Avatar answered Sep 30 '22 01:09

The Who