从另一个调用控制器 [英] Calling a controller from another

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

问题描述

我想从另一个控制器调用控制器的操作。



我如何做?



最好的祝福

解决方案

您不能调用其他控制器的操作方法。

您只有两种解决方案。



重定向到相应的网址。

  redirect_to'/'

但是当然,如​​果你有一个表单的数据,你会失去它们。



控制器。

 渲染控制器/操作

你保留所有你定义的数据(params和一切)。

但是你需要再做所有其他控制器的工作。



避免重复代码行的一个解决方案是使用一个库方法定义你的视图中需要的每个var,并在两个控制器中使用这个方法。


I want to call an action of a controller from another controller.

How can I do this?

Some years ago, there were compononents, but they are not available any more.

Best regards

解决方案

You can't call an other controller's action method.
You have only two solutions.

Doing a redirect to the appropriate URL.

redirect_to '/'

But of course if you have datas from a form, you lose them.

Render the action from an other controller.

render 'controller/action'

You keep all your defined datas (params and everything).
But you need to do again all what the other controller would do.

One solution to avoid repeating code lines would be to have a library method defining every vars you need in your view and use this method in your two controllers.

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

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