What is the Rails Presenters folder for? What goes in this folder? Why is this folder needed?
Rails呈现程序文件夹的用途是什么?这个文件夹里有什么?为什么需要这个文件夹?
(Hitting 'Post your Question' while peaking put through a gap in my hand)
(点击“发布你的问题”,同时在我的手中插入一个空隙)
2 个解决方案
#1
3
presenters
is a design pattern commonly reffered to as Model View Presenter(MVP)
主持人是一种设计模式,通常作为模型视图主持人(MVP)
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.
它对于分离关注点以使代码更加枯燥是有用的。
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
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter
Presenters in Ruby on Rails
Ruby on Rails的演示者
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.
呈现器是介于模型和视图之间的简单类,它提供了一种良好的、面向对象的处理复杂显示逻辑的方式。
In Rails, the convention is for them to be located in the app/presenters
folder
在Rails中,约定是将它们放在app/presenter文件夹中
Here is a userful article that explains the pattern and its use in Ruby on Rails.
下面是一篇解释Ruby on Rails模式及其使用的文章。
https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/
https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/
#2
4
The Presenters folder is where your Presenter code would go... I know, obvious, I'll explain... The way I think of Presenters and Decorators is as an abstraction of a Model in order to massage the data attributes before they are given to the view. If you are familiar with helpers, well, Presenters are kind of like helpers in the sense that they are getting some data ready for the view, except helpers usually serve as utility methods for said views, while presenters are more about presenting the actual attributes.
演示者文件夹是你的演示者代码所在的地方……我知道,很明显,我会解释……我认为呈现者和装饰者是模型的抽象,以便在数据属性被提供给视图之前对它们进行调整。如果您熟悉helper函数,那么从某种意义上讲,表示程序类似于helper函数,它们为视图准备了一些数据,但是表示程序通常作为上述视图的实用方法,而表示程序更多的是表示实际的属性。
This link explains the difference very well: https://robertomurray.co.uk/blog/2014/decorators-presenters-delegators-rails/
这个链接很好地解释了这一差异:https://robertomurray.co.uk/blog/2014/decorators-presenters-rails/。
hope that helps.
希望有帮助。
#1
3
presenters
is a design pattern commonly reffered to as Model View Presenter(MVP)
主持人是一种设计模式,通常作为模型视图主持人(MVP)
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.
它对于分离关注点以使代码更加枯燥是有用的。
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
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter
Presenters in Ruby on Rails
Ruby on Rails的演示者
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.
呈现器是介于模型和视图之间的简单类,它提供了一种良好的、面向对象的处理复杂显示逻辑的方式。
In Rails, the convention is for them to be located in the app/presenters
folder
在Rails中,约定是将它们放在app/presenter文件夹中
Here is a userful article that explains the pattern and its use in Ruby on Rails.
下面是一篇解释Ruby on Rails模式及其使用的文章。
https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/
https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/
#2
4
The Presenters folder is where your Presenter code would go... I know, obvious, I'll explain... The way I think of Presenters and Decorators is as an abstraction of a Model in order to massage the data attributes before they are given to the view. If you are familiar with helpers, well, Presenters are kind of like helpers in the sense that they are getting some data ready for the view, except helpers usually serve as utility methods for said views, while presenters are more about presenting the actual attributes.
演示者文件夹是你的演示者代码所在的地方……我知道,很明显,我会解释……我认为呈现者和装饰者是模型的抽象,以便在数据属性被提供给视图之前对它们进行调整。如果您熟悉helper函数,那么从某种意义上讲,表示程序类似于helper函数,它们为视图准备了一些数据,但是表示程序通常作为上述视图的实用方法,而表示程序更多的是表示实际的属性。
This link explains the difference very well: https://robertomurray.co.uk/blog/2014/decorators-presenters-delegators-rails/
这个链接很好地解释了这一差异:https://robertomurray.co.uk/blog/2014/decorators-presenters-rails/。
hope that helps.
希望有帮助。