简体   繁体   English

rails 有没有办法拦截 controller 请求?

[英]Is there a way in rails to intercept controller requests?

I don't think Rails calls it an interceptor, but I don't know what to search for.我不认为 Rails 称它为拦截器,但我不知道要搜索什么。

In Java/Spring, you can create Interceptors that are called before and after any controller action in the MVC framework.在 Java/Spring 中,您可以创建在 MVC 框架中的任何 controller 操作之前和之后调用的拦截器。 This makes it easy to add data to the model for every request, so you don't have to keep adding it to each of your 50 controllers.这使得为每个请求向 model 添加数据变得很容易,因此您不必继续将数据添加到您的 50 个控制器中的每一个。

I have to take a wild guess and say Rails has something to do achieve the same effect... but I have no idea what it is called.我不得不大胆猜测并说 Rails 有一些事情要做以达到相同的效果......但我不知道它叫什么。

Care to share?愿意分享吗? :) :)

What you are looking for is called Filters.您正在寻找的是所谓的过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM