从另一个控制器渲染控制器操作

时间:2010-07-30 09:30:51

标签: ruby-on-rails routing rendering ruby-on-rails-3

我认为代码更明确

选项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)可以在另一个控制器中加载另一个动作吗? (而不只是视图)怎么样? 谢谢

2 个答案:

答案 0 :(得分:42)

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

答案 1 :(得分:2)

只需渲染模板

 string script = "$(document).ready(function () { $('[id*=form1]').load(); });";
 ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);

这个也有效

import { bootstrap }    from '@angular/platform-browser-dynamic';

import { AppComponent } from './app.component';
import { disableDeprecatedForms, provideForms} from '@angular/forms';

bootstrap(AppComponent, [
  disableDeprecatedForms(),
  provideForms()
]);

如果您想要渲染其他布局

def index
  render 'posts/show'
end