gpt4 book ai didi

ruby-on-rails - 从另一个 Controller 渲染 Controller Action

转载 作者:行者123 更新时间:2023-12-03 10:36:05 25 4
gpt4 key购买 nike

我认为代码更明确

选项A

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

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

(B)中是否可以在另一个 Controller 中加载另一个 Action ? (而不仅仅是 View )如何?
谢谢

最佳答案

尝试render 'posts/show'render :template => 'posts/show'

关于ruby-on-rails - 从另一个 Controller 渲染 Controller Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3370234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com