{"id":265524,"date":"2015-09-13T16:06:04","date_gmt":"2015-09-13T12:06:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=265524"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=265524","title":{"rendered":"\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0430 ruby on rails. \u0427\u0430\u0441\u0442\u044c 1"},"content":{"rendered":"<p>       <cut\/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u044f \u0441\u043e\u0431\u0435\u0440\u0443 \u0431\u041e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0432\u043e\u0435\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Ruby on Rails. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u043d\u0435 \u044f, \u0438, \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0431\u0443\u0434\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a. <\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 RoR \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0422.\u0435. \u043a\u043e\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044f\u0445(ActiveRecord::Base), \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u0445\u044d\u043b\u043f\u0435\u0440\u0430\u0445 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c: \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c, \u0434\u043e\u043b\u0433\u043e \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u0444\u0438\u0447\u0438, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 <a href=\"https:\/\/github.com\/redmine\/redmine\/blob\/master\/app%2Fmodels%2Fissue.rb\">redmine<\/a>.<\/p>\n<p>  \u0412\u044b\u0445\u043e\u0434 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e-\u0442\u0430\u043a\u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439. \u0411\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0435 \u043d\u0430 ruby on rails, \u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c ruby on rails. \u041a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c: \u043c\u044b \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0443\u0445\u043e\u0434\u0438\u043c \u043e\u0442 MVC \u0438 Rails, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0438\u043c Model, View, Controller. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a ORM. \u041c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0432\u0441\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f: \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0444\u043e\u0440\u043c\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0434\u0430\u043b\u0435\u0435. \u0422\u0430\u043a \u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b, \u0445\u0435\u043b\u043f\u0435\u0440\u044b, \u0431\u0438\u043b\u0434\u0435\u0440\u044b \u0444\u043e\u0440\u043c. \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, responders.<cut\/><\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0438\u043a \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u043e SOLID, ruby style guide, rails conventions, ruby object model, ruby metaprogramming, \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c. <\/p>\n<h2>Helpers<\/h2>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043e\u0432\u0435\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u044b. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0438\u0445 \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code>module ApplicationHelper   def menu_item(model, action, name, url, link_options = {})     return unless policy(model).send &quot;#{action}?&quot;     content_tag :li do       link_to name, url, link_options     end   end end  # _nav.haml = menu_item current_user, :show, t(:show_profile), user_path(current_user) = menu_item current_user, :edit, t(:edit_profile), edit_user_path(current_user) <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 menu_item \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u043b\u0438\u0442\u0438\u043a. \u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0445\u044d\u043b\u043f\u0435\u0440, \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044e.<\/p>\n<pre><code>module ApplicationHelper   def han(model, attribute)     model.to_s.classify.constantize.human_attribute_name(attribute)   end    def show_attribute(model, attribute)     value = model.send(attribute)     return if value.blank?     [         content_tag(:dt, han(model.model_name, attribute)),         content_tag(:dd, value)     ].join.html_safe   end end  # show.haml  = show_attribute user_presenter, :name  = show_attribute user_presenter, :role_text  = show_attribute user_presenter, :profile_image <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 show_attribute \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0435\u0441\u0442\u044c. <\/p>\n<h2>Form templates<\/h2>\n<p>  <\/p>\n<pre><code>= simple_form_for @user, builder: PunditFormBuilder do |f|   = f.input :name   = f.input :contacts, as: :big_textarea   # some other inputs   = f.button :submit <\/code><\/pre>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e gem simple_form \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0444\u043e\u0440\u043c. \u042d\u0442\u043e\u0442 \u0433\u0435\u043c \u0431\u0435\u0440\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0444\u043e\u0440\u043c. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u0441\u043a\u0438\u0445 \u0444\u043e\u0440\u043c \u044d\u0442\u043e\u0442 \u0433\u0435\u043c \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e. <\/p>\n<p>  \u041f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435: \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0442\u0438\u043f. \u0422\u0435\u043a\u0441\u0442\u044b \u0434\u043b\u044f labels, placeholders, submit \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438:<\/p>\n<pre><code>ru:   attributes:     created_at: \u0421\u043e\u0437\u0434\u0430\u043d\u043e   activerecord:     attributes:       user:         name: \u0418\u043c\u044f   helpers:     submit:       create: \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0441\u0432\u043e\u0438 inputs. <br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c 10 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code>class BigTextareaInput &lt; SimpleForm::Inputs::TextInput   def input_html_options     { rows: 10 }   end end <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043d\u043f\u0443\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0431\u043e\u0440, \u0432 \u043a\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u044c (gem state_machines).<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 SimpleForm \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0431\u0438\u043b\u0434\u0435\u0440\u044b \u0444\u043e\u0440\u043c:<\/p>\n<pre><code>class PunditFormBuilder &lt; SimpleForm::FormBuilder   def input(attribute_name, options = {}, &amp;block)     return unless show_attribute? attribute_name     super(attribute_name, options, &amp;block)   end    def show_attribute?(attr_name)     # some code   end end  = simple_form_for @user, builder: PunditFormBuilder do |f| <\/code><\/pre>\n<p>  PunditFormBuilder \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0433\u043b\u0430\u0432\u0435 \u043f\u0440\u043e ACL.<\/p>\n<h2>Serializers<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 http json api. \u0412\u043e\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b:  <\/p>\n<ul>\n<li>\u043c\u0435\u0442\u043e\u0434 <code>Model#to_json<\/code><\/li>\n<li>\u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0440\u043e\u043b\u043b\u0435\u0440\u0430 serialize_model<\/li>\n<\/ul>\n<p>  \u0412\u0441\u0435 \u044d\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0430\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 MVC. \u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u043a\u043e\u043d\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u2014 \u044d\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u042f \u0432\u0438\u0436\u0443 2 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:  <\/p>\n<ul>\n<li>\u0448\u0430\u0431\u043b\u043e\u043d\u044b jbuilder<\/li>\n<li>serializers, \u043f\u0440\u0438\u0447\u0435\u043c \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u0439 gem, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b (\u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u044b?)<\/li>\n<\/ul>\n<pre><code>class CommentSerializer &lt; ActiveModel::Serializer   attributes :name, :body    belongs_to :post end <\/code><\/pre>\n<p>  \u0422.\u0435. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0445\u044d\u043b\u043f\u0435\u0440\u044b, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u044b.<\/p>\n<h2>Presenters<\/h2>\n<p>  \u0422\u0430\u043a \u043c\u044b \u043f\u043b\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u043e\u0432. \u0412 rails \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u043e\u0432.<\/p>\n<p>  gem drapper \u0432\u043d\u0435\u0441 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443: \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0425\u043e\u0442\u044f \u044d\u0442\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u043e\u0445\u043e\u0436\u0438, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u0422\u0430\u043a \u0436\u0435 \u0441 \u044d\u0442\u0438\u043c \u0433\u0435\u043c\u043e\u043c \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e <a href=\"https:\/\/github.com\/drapergem\/draper\/issues\/655\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/a> (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a issues).<\/p>\n<p>  \u042f \u043d\u0430\u0448\u0435\u043b <a href=\"http:\/\/nithinbekal.com\/posts\/rails-presenters\/\">\u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b<\/a>. \u041d\u0438\u0436\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<pre><code># app\/presenters\/base_presenter.rb class BasePresenter &lt; Delegator   attr_reader :model, :h   alias_method :__getobj__, :model    def initialize(model, view_context)     @model = model     @h = view_context   end    def inspect     &quot;#&lt;#{self.class} model: #{model.inspect}&gt;&quot;   end end <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0435\u0439 \u043c\u0435\u0442\u043e\u0434\u044b. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u0430\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440. \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <a href=\"http:\/\/ruby-doc.org\/stdlib-2.1.0\/libdoc\/delegate\/rdoc\/Delegator.html\">Delegator<\/a> \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u0441\u043e\u0434\u0435\u0436\u0438\u0442 view_context, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u0437\u0432\u0430\u043d &#8216;h&#8217;. <br \/>  \u042d\u0442\u043e self, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0432 helpers \u0438 views. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u044b.<\/p>\n<pre><code># app\/presenters\/task_presenter.rb class TaskPresenter &lt; BasePresenter   def to_link     h.link_to model.to_s, model   end    def description     h.markdown model.description   end    # \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c   def users     model.users.map { |user| h.present user }   end end <\/code><\/pre>\n<pre><code># app\/helpers\/application_helper.rb def present(model)   return if model.blank?   klass = &quot;#{model.class}Presenter&quot;.constantize   presenter = klass.new(model, self)   yield(presenter) if block_given?   presenter end <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 present \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442-\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u0432 \u0431\u043b\u043e\u043a \u0438\u043b\u0438 \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. <br \/>  \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0447\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445:<\/p>\n<pre><code># app\/views\/web\/tasks\/index.haml - @tasks.each do |task|   %tr     - present task do |task_presenter|       %td= task_presenter.id       %td= task_presenter.to_link       %td= task_presenter.project <\/code><\/pre>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0445\u044d\u043b\u043f\u0435\u0440\u0435\u0440\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442. \u0418\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0434\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0432\u043e\u0434 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0435\u043d\u044e \u0438\u043b\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<pre><code>class MenuRenderer   attr_reader :h    def initialize(view_context)     @h = view_context   end    def render     some_hard_logic   end    private   def some_hard_logic     h.link_to '', ''   end end <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u2014 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u043c\u043e\u0434\u0435\u043b\u0438. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e: form-objects, services, ACL, query-objects, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u043c\u0438.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/266761\/\"> http:\/\/habrahabr.ru\/post\/266761\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <cut\/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u044f \u0441\u043e\u0431\u0435\u0440\u0443 \u0431\u041e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0432\u043e\u0435\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Ruby on Rails. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u043d\u0435 \u044f, \u0438, \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0431\u0443\u0434\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a. <\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 RoR \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0422.\u0435. \u043a\u043e\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044f\u0445(ActiveRecord::Base), \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u0445\u044d\u043b\u043f\u0435\u0440\u0430\u0445 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c: \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c, \u0434\u043e\u043b\u0433\u043e \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u0444\u0438\u0447\u0438, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 <a href=\"https:\/\/github.com\/redmine\/redmine\/blob\/master\/app%2Fmodels%2Fissue.rb\">redmine<\/a>.<\/p>\n<p>  \u0412\u044b\u0445\u043e\u0434 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e-\u0442\u0430\u043a\u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439. \u0411\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0435 \u043d\u0430 ruby on rails, \u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c ruby on rails. \u041a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c: \u043c\u044b \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0443\u0445\u043e\u0434\u0438\u043c \u043e\u0442 MVC \u0438 Rails, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0438\u043c Model, View, Controller. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a ORM. \u041c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0432\u0441\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041c\u043e\u0434\u0435\u043b\u044c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f: \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0444\u043e\u0440\u043c\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0434\u0430\u043b\u0435\u0435. \u0422\u0430\u043a \u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b, \u0445\u0435\u043b\u043f\u0435\u0440\u044b, \u0431\u0438\u043b\u0434\u0435\u0440\u044b \u0444\u043e\u0440\u043c. \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, responders.<cut\/><\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0438\u043a \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u043e SOLID, ruby style guide, rails conventions, ruby object model, ruby metaprogramming, \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c. <\/p>\n<h2>Helpers<\/h2>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043e\u0432\u0435\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u044b. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0438\u0445 \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code>module ApplicationHelper   def menu_item(model, action, name, url, link_options = {})     return unless policy(model).send &quot;#{action}?&quot;     content_tag :li do       link_to name, url, link_options     end   end end  # _nav.haml = menu_item current_user, :show, t(:show_profile), user_path(current_user) = menu_item current_user, :edit, t(:edit_profile), edit_user_path(current_user) <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 menu_item \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u043b\u0438\u0442\u0438\u043a. \u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0445\u044d\u043b\u043f\u0435\u0440, \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044e.<\/p>\n<pre><code>module ApplicationHelper   def han(model, attribute)     model.to_s.classify.constantize.human_attribute_name(attribute)   end    def show_attribute(model, attribute)     value = model.send(attribute)     return if value.blank?     [         content_tag(:dt, han(model.model_name, attribute)),         content_tag(:dd, value)     ].join.html_safe   end end  # show.haml  = show_attribute user_presenter, :name  = show_attribute user_presenter, :role_text  = show_attribute user_presenter, :profile_image <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 show_attribute \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0435\u0441\u0442\u044c. <\/p>\n<h2>Form templates<\/h2>\n<p>  <\/p>\n<pre><code>= simple_form_for @user, builder: PunditFormBuilder do |f|   = f.input :name   = f.input :contacts, as: :big_textarea   # some other inputs   = f.button :submit <\/code><\/pre>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e gem simple_form \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0444\u043e\u0440\u043c. \u042d\u0442\u043e\u0442 \u0433\u0435\u043c \u0431\u0435\u0440\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0444\u043e\u0440\u043c. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u0441\u043a\u0438\u0445 \u0444\u043e\u0440\u043c \u044d\u0442\u043e\u0442 \u0433\u0435\u043c \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e. <\/p>\n<p>  \u041f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435: \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0442\u0438\u043f. \u0422\u0435\u043a\u0441\u0442\u044b \u0434\u043b\u044f labels, placeholders, submit \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438:<\/p>\n<pre><code>ru:   attributes:     created_at: \u0421\u043e\u0437\u0434\u0430\u043d\u043e   activerecord:     attributes:       user:         name: \u0418\u043c\u044f   helpers:     submit:       create: \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0441\u0432\u043e\u0438 inputs. <br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c 10 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code>class BigTextareaInput &lt; SimpleForm::Inputs::TextInput   def input_html_options     { rows: 10 }   end end <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043d\u043f\u0443\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0431\u043e\u0440, \u0432 \u043a\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u044c (gem state_machines).<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 SimpleForm \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0431\u0438\u043b\u0434\u0435\u0440\u044b \u0444\u043e\u0440\u043c:<\/p>\n<pre><code>class PunditFormBuilder &lt; SimpleForm::FormBuilder   def input(attribute_name, options = {}, &amp;block)     return unless show_attribute? attribute_name     super(attribute_name, options, &amp;block)   end    def show_attribute?(attr_name)     # some code   end end  = simple_form_for @user, builder: PunditFormBuilder do |f| <\/code><\/pre>\n<p>  PunditFormBuilder \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0433\u043b\u0430\u0432\u0435 \u043f\u0440\u043e ACL.<\/p>\n<h2>Serializers<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 http json api. \u0412\u043e\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b:  <\/p>\n<ul>\n<li>\u043c\u0435\u0442\u043e\u0434 <code>Model#to_json<\/code><\/li>\n<li>\u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0440\u043e\u043b\u043b\u0435\u0440\u0430 serialize_model<\/li>\n<\/ul>\n<p>  \u0412\u0441\u0435 \u044d\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0430\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 MVC. \u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u043a\u043e\u043d\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u2014 \u044d\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u042f \u0432\u0438\u0436\u0443 2 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:  <\/p>\n<ul>\n<li>\u0448\u0430\u0431\u043b\u043e\u043d\u044b jbuilder<\/li>\n<li>serializers, \u043f\u0440\u0438\u0447\u0435\u043c \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u0439 gem, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b (\u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u044b?)<\/li>\n<\/ul>\n<pre><code>class CommentSerializer &lt; ActiveModel::Serializer   attributes :name, :body    belongs_to :post end <\/code><\/pre>\n<p>  \u0422.\u0435. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0445\u044d\u043b\u043f\u0435\u0440\u044b, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0435\u0440\u0438\u0430\u043b\u0430\u0439\u0437\u0435\u0440\u044b.<\/p>\n<h2>Presenters<\/h2>\n<p>  \u0422\u0430\u043a \u043c\u044b \u043f\u043b\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u043e\u0432. \u0412 rails \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u043e\u0432.<\/p>\n<p>  gem drapper \u0432\u043d\u0435\u0441 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0443: \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0425\u043e\u0442\u044f \u044d\u0442\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u043e\u0445\u043e\u0436\u0438, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u0422\u0430\u043a \u0436\u0435 \u0441 \u044d\u0442\u0438\u043c \u0433\u0435\u043c\u043e\u043c \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e <a href=\"https:\/\/github.com\/drapergem\/draper\/issues\/655\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/a> (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a issues).<\/p>\n<p>  \u042f \u043d\u0430\u0448\u0435\u043b <a href=\"http:\/\/nithinbekal.com\/posts\/rails-presenters\/\">\u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u044b<\/a>. \u041d\u0438\u0436\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<pre><code># app\/presenters\/base_presenter.rb class BasePresenter &lt; Delegator   attr_reader :model, :h   alias_method :__getobj__, :model    def initialize(model, view_context)     @model = model     @h = view_context   end    def inspect     &quot;#&lt;#{self.class} model: #{model.inspect}&gt;&quot;   end end <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0435\u0439 \u043c\u0435\u0442\u043e\u0434\u044b. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u0430\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440. \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <a href=\"http:\/\/ruby-doc.org\/stdlib-2.1.0\/libdoc\/delegate\/rdoc\/Delegator.html\">Delegator<\/a> \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u0441\u043e\u0434\u0435\u0436\u0438\u0442 view_context, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u0437\u0432\u0430\u043d &#8216;h&#8217;. <br \/>  \u042d\u0442\u043e self, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0432 helpers \u0438 views. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0445\u044d\u043b\u043f\u0435\u0440\u044b.<\/p>\n<pre><code># app\/presenters\/task_presenter.rb class TaskPresenter &lt; BasePresenter   def to_link     h.link_to model.to_s, model   end    def description     h.markdown model.description   end    # \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c   def users     model.users.map { |user| h.present user }   end end <\/code><\/pre>\n<pre><code># app\/helpers\/application_helper.rb def present(model)   return if model.blank?   klass = &quot;#{model.class}Presenter&quot;.constantize   presenter = klass.new(model, self)   yield(presenter) if block_given?   presenter end <\/code><\/pre>\n<p>  \u0425\u044d\u043b\u043f\u0435\u0440 present \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442-\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0435\u0440 \u0432 \u0431\u043b\u043e\u043a \u0438\u043b\u0438 \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. <br \/>  \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0447\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445:<\/p>\n<pre><code># app\/views\/web\/tasks\/index.haml - @tasks.each do |task|   %tr     - present task do |task_presenter|       %td= task_presenter.id       %td= task_presenter.to_link       %td= task_presenter.project <\/code><\/pre>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0445\u044d\u043b\u043f\u0435\u0440\u0435\u0440\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442. \u0418\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0434\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0432\u043e\u0434 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0435\u043d\u044e \u0438\u043b\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<pre><code>class MenuRenderer   attr_reader :h    def initialize(view_context)     @h = view_context   end    def render     some_hard_logic   end    private   def some_hard_logic     h.link_to '', ''   end end <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u2014 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u043c\u043e\u0434\u0435\u043b\u0438. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e: form-objects, services, ACL, query-objects, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u043c\u0438.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/266761\/\"> http:\/\/habrahabr.ru\/post\/266761\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-265524","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265524"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265524\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}