从另一个控制器渲染控制器动作 [英] Render controller action from another controller

查看:112
本文介绍了从另一个控制器渲染控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为代码更明确

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



选项B



option B

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

(B)中是否可以在另一个控制器中加载另一个动作? (而不仅仅是视图)如何?
谢谢

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

推荐答案

尝试渲染帖子/节目 render:template => 帖子/节目

这篇关于从另一个控制器渲染控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆