Rails 3 render action from another controller

Solution 1:

Try to render template:

<%= render :template => "controller/index" %> 

Or file:

<%= render :template => "#{Rails.root}/app/controllers/controller/index" %> 

And I believe you should render it through controller, as far as it is more convenient:

def your_action
  ...
  render :action => :index
end

Solution 2:

This works well for me :

def renderActionInOtherController(controller,action,params)
  controller.class_eval{
    def params=(params); @params = params end
    def params; @params end
  }
  c = controller.new
  c.request = @_request
  c.response = @_response
  c.params = params
  c.send(action)
  c.response.body
end

then, call by

render :text => renderActionInOtherController(OtherController,:otherAction,params)

basically it hacks the other class and overwrites its "params" method and return

If you are using Rails 4:

def renderActionInOtherController(controller,action,params)
    c = controller.new
    c.params = params
    c.dispatch(action, request)
    c.response.body
end