# Showing another controllers action

**URL:** <https://www.ruby-forum.com/t/showing-another-controllers-action/142725>\
**Category:** Rails\
**Created:** [July 10, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725 "2008-07-10T21:24:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 10, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/1 "2008-07-10T21:24:18Z")

</div>

If I am in controller A and I want to show the index of controller B,  
how would I do that?

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 10, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/2 "2008-07-10T22:31:35Z")

</div>

Wouldn’t you just do a simple redirect?

def create  
@scenario = Scenario.new(params[:scenario])  
if @scenario.save  
flash[:notice] = ‘Scenario was successfully created.’  
# where do we return to?  
case params[:from\_type]  
when ‘project’  
redirect\_to projectview\_path(params[:from\_id])  
else  
redirect\_to scenarioviews\_path  
end  
else  
render :action =\> “new”  
end  
end

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 10, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/3 "2008-07-10T22:38:22Z")

</div>

Ar Chron wrote:

> Wouldn’t you just do a simple redirect?
> 
> def create  
> @scenario = Scenario.new(params[:scenario])  
> if @scenario.save  
> flash[:notice] = ‘Scenario was successfully created.’  
> # where do we return to?  
> case params[:from\_type]  
> when ‘project’  
> redirect\_to projectview\_path(params[:from\_id])  
> else  
> redirect\_to scenarioviews\_path  
> end  
> else  
> render :action =\> “new”  
> end  
> end

No, I dont want to redirect to another controller. I want to stay in my  
current controller.

Here is what I did:

from my controller A I ran an RJS file.  
The RJS file replaces my content area with a partial.  
My partial uses one line of code

\<%= render\_file “CONTROLLER\_B\_NAME/index.html.erb” %\>

If anybody else knows a better why, I’d be appreciative to hear it.

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 11, 2008, 2:21am UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/4 "2008-07-11T02:21:49Z")

</div>

In controller A:

render :controller\_b, :action =\> “your\_action”

On Jul 11, 8:38 am, Joel Saltzmanjoelh \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> > ```
> > redirect_to projectview_path(params[:from_id])
> > 
> > ```
> 
> Po  
> sted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 11, 2008, 4:15am UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/5 "2008-07-11T04:15:04Z")

</div>

Phil wrote:

> In controller A:
> 
> render :controller\_b, :action =\> “your\_action”
> 
> On Jul 11, 8:38 am, Joel Saltzmanjoelh \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > > ```
> > > redirect_to projectview_path(params[:from_id])
> > > 
> > > ```
> > 
> > Po  
> > sted viahttp://www.ruby-forum.com/.

That doesnt work at all…

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 11, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/6 "2008-07-11T17:21:15Z")

</div>

On Jul 10, 10:15 pm, Joel Saltzmanjoelh \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Phil wrote:
> 
> > In controller A:
> 
> > render :controller\_b, :action =\> “your\_action”

I believe it’s:

render(:controller =\> “controller\_name”, :action =\> “your\_action”)

I haven’t tried it, but that’s the syntax for redirect\_to

HTH.

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 11, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/7 "2008-07-11T22:44:41Z")

</div>

render :template =\> “foo/bar”

On Jul 11, 12:35Â pm, Joel Saltzmanjoelh \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![jsamildanach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@jsamildanach](https://www.ruby-forum.com/u/jsamildanach)\
**Post date:** [July 11, 2008, 6:35pm UTC](https://www.ruby-forum.com/t/showing-another-controllers-action/142725/8 "2008-07-11T18:35:38Z")

</div>

greenideas wrote:

> On Jul 10, 10:15ï¿½pm, Joel Saltzmanjoelh \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > Phil wrote:
> > 
> > > In controller A:
> > 
> > > render :controller\_b, :action =\> “your\_action”
> 
> I believe it’s:
> 
> render(:controller =\> “controller\_name”, :action =\> “your\_action”)
> 
> I haven’t tried it, but that’s the syntax for redirect\_to
> 
> HTH.

Thanks, that doesnt work for rendering though. oh well.
