简体   繁体   English

Rails视图如何获得对问题的访问?

[英]How do Rails views get access to concerns?

I've been learning Rails and seems like concerns are a way to dry up fat models and make methods sharable by models. 我一直在学习Rails,似乎关注的是干掉脂肪模型并使方法可以被模型共享的方法。 I'm confused though as to why views/partials have access to these methods. 我很困惑,为什么views / partials可以访问这些方法。 Shouldn't the MVC model make all the model related things go through the controller and then be given to the view. MVC模型不应该使所有与模型相关的东西通过控制器然后被赋予视图。 It feels like giving views access directly to model concerns skips the controller. 感觉就像直接向模型问题提供视图访问权限会跳过控制器。 Also why do I not have access to these methods in Rails console? 另外,为什么我无法在Rails控制台中访问这些方法?

A model concern can be seen as a way to split up a model with many methods. 可以将模型关注视为使用多种方法拆分模型的方法。 It is possible to share common methods between models, but also possible to just thin out the model code. 可以在模型之间共享通用方法,但也可以简化模型代码。

Once you include the concern, all concern methods are mixed into the model, and therefore are available anywhere the 'base' model methods are. 一旦您考虑到问题,所有关注方法都会混合到模型中,因此可以在“基础”模型方法的任何位置使用。

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

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