Render controller action from another controller

user142913 picture user142913 · Jul 30, 2010 · Viewed 52.6k times · Source

I think the code is more explicit

option A

class RedirectController < ApplicationController
  def index
    redirect_to :controller => 'posts', :action => 'show', :id => 1
    # it works
  end
end

option B

class RedirectController < ApplicationController
  def index
    render :controller => 'posts', :action => 'show', :id => 1
    # it doesn't work
  end
end

Is possible in (B) to load another action in another controller? (and not just the view) How? Thanks

Answer

Bohdan picture Bohdan · Jul 30, 2010

Try render 'posts/show' or render :template => 'posts/show'