Rails Presenters文件夹有什么用? [英] What is the Rails Presenters folder for?

查看:104
本文介绍了Rails Presenters文件夹有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails Presenters文件夹有什么用?该文件夹中有什么?为什么需要此文件夹?

What is the Rails Presenters folder for? What goes in this folder? Why is this folder needed?

推荐答案

presenters是一种通常称为Model View Presenter(MVP)的设计模式.

presenters is a design pattern commonly reffered to as Model View Presenter(MVP)

这是Model View Controller模式的派生,用于创建用户界面.

This is a derivation of the Model View Controller pattern and is used for creating user interfaces.

对于使代码更干燥的关注点分离很有用.

It's useful for the Separation of Concerns for making code more DRY.

这是Wikipedia的描述方式

Here's how Wikipedia describes it

模型-定义要在用户界面中显示或以其他方式作用的数据的界面.

model - interface defining the data to be displayed or otherwise acted upon in the user interface.

演示者-作用于模型和视图.它从存储库(模型)中检索数据,并将其格式化以在视图中显示.

presenter - acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

视图-一个被动界面,用于显示数据(模型)并将用户命令(事件)路由到演示者以对该数据进行操作.

view - a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter

Ruby on Rails中的演示器

Presenters是位于模型和视图之间的简单类,它们提供了一种很好的,面向DRY对象的方式来处理复杂的显示逻辑.

Presenters are simple classes that sit between the model and the view and provide provide a nice, DRY object oriented way of working with complex display logic.

在Rails中,约定将它们放置在app/presenters文件夹中

In Rails, the convention is for them to be located in the app/presenters folder

这是一篇引人入胜的文章,介绍了该模式及其在Ruby on Rails中的用法.

Here is a userful article that explains the pattern and its use in Ruby on Rails.

https://kpumuk.info/ruby -on-rails/简化您的ruby-on-rails代码/

这篇关于Rails Presenters文件夹有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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