{"id":158011,"date":"2012-11-09T14:15:05","date_gmt":"2012-11-09T10:15:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=158011"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=158011","title":{"rendered":"<span class=\"post_title\">7 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0442\u043e\u043b\u0441\u0442\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 Rails<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0422\u043e\u043b\u0441\u0442\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435. \u041e\u043d\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043d\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Single_responsibility_principle\">Single Responsibility Principle<\/a>(SRP). \u201c\u0412\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u201d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f single responsibility.<br \/>  \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 SRP \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e. \u041d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0434\u0435-\u0444\u0430\u043a\u0442\u043e \u043c\u0435\u0441\u0442\u043e\u043c \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438. \u0418 \u0441\u043f\u0443\u0441\u0442\u044f \u0434\u0432\u0430 \u0433\u043e\u0434\u0430 \u0443 \u043c\u043e\u0434\u0435\u043b\u0438 User \u0431\u043e\u043b\u044c\u0448\u0435 500 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u0438 50 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 public.<br \/>  \u0426\u0435\u043b\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0442\u0443\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0438 \u043c\u043e\u0434\u0443\u043b\u044f\u043c. Fat models, skinny controllers \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0432 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435, \u0442\u0430\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0438 \u0432\u0442\u043e\u0440\u043e\u0439.<a name=\"habracut\"><\/a><br \/>  \u0412\u044b, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0432 Rails \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u041e\u041e\u041f. \u042f \u0442\u043e\u0436\u0435 \u0442\u0430\u043a \u0434\u0443\u043c\u0430\u043b. \u041d\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0439 \u0438 \u043e\u043f\u044b\u0442\u043e\u0432 \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e Rails \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u0435\u0448\u0430\u0435\u0442 \u041e\u041e\u041f. \u0421\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f Rails \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442. \u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OO\u041f \u0438 best practices \u0442\u0430\u043c, \u0433\u0434\u0435 Rails \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442.<\/p>\n<h4>\u041d\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0439\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044f\u043c<\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e. \u042f \u043d\u0435 \u043e\u0434\u043e\u0431\u0440\u044f\u044e \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u043c\u043e\u0434\u0443\u043b\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0440\u0430\u0441\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0435\u0449\u0438 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u043f\u043e\u0434 \u043a\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 \u0448\u043a\u0430\u0444. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u043e\u0434\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435, \u043d\u043e \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0442\u044f\u0436\u0435\u043b\u043e.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435.<\/p>\n<h4>1. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Value Objects<\/h4>\n<p>  <a href=\"http:\/\/c2.com\/cgi\/wiki?ValueObject\">Value Objects<\/a> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0434\u0435\u043d\u044c\u0433\u0438 \u0438\u043b\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0434\u0430\u0442, \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. Date, URI, Pathname \u2014 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Ruby, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0438.<br \/>  \u0412 Rails Value Objects \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043d\u0438\u043c\u0438 \u043b\u043e\u0433\u0438\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0421\u041c\u0421 \u0431\u044b\u043b PhoneNumber. \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u043d\u0443\u0436\u0435\u043d Money. \u0423 Code Climate \u0435\u0441\u0442\u044c Rating \u2014 \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u042f \u043c\u043e\u0433 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c String, \u043d\u043e \u0432 Rating \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u043b\u043e\u0433\u0438\u043a\u0430:  <\/p>\n<pre><code class=\"ruby\">class Rating  include Comparable   def self.from_cost(cost)     if cost &lt;= 2 new(&quot;A&quot;)     elsif cost &lt;= 4 new(&quot;B&quot;)     elsif cost &lt;= 8 new(&quot;C&quot;)     elsif cost &lt;= 16 new(&quot;D&quot;)     else new(&quot;F&quot;)     end   end    def initialize(letter)     @letter = letter    end    def better_than?(other)      self &gt; other    end     def &lt;=&gt;(other)      other.to_s &lt;=&gt; to_s   end    def hash     @letter.hash    end     def eql?(other)     to_s == other.to_s   end     def to_s     @letter.to_s   end  end <\/code><\/pre>\n<p>  \u0418 \u0443 ConstantSnapshot \u0435\u0441\u0442\u044c Rating:  <\/p>\n<pre><code class=\"ruby\">class ConstantSnapshot &lt; ActiveRecord::Base   #\u2026   def rating     @rating ||= Rating.from_cost(cost)   end end  <\/code><\/pre>\n<p>  \u041f\u043b\u044e\u0441\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:  <\/p>\n<ul>\n<li>\u041b\u043e\u0433\u0438\u043a\u0430 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0430 \u0438\u0437 ConstantSnapshot<\/li>\n<li>\u0421 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 #hash \u0438 #eql? \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0439\u0442\u0438\u043d\u0433 \u043a\u0430\u043a \u0445\u044d\u0448. Code Climate \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e \u0434\u043b\u044f \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u043e \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Enumerable#group_by.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>2. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Service Objects<\/h4>\n<p>  \u042f \u0441\u043e\u0437\u0434\u0430\u044e Service Objects \u0435\u0441\u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435:  <\/p>\n<ul>\n<li>\u0441\u043b\u043e\u0436\u043d\u043e\u0435(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0432\u0441\u0435\u0445 \u043a\u043d\u0438\u0433 \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e an accounting period)<\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b Order, CreditCard \u0438 Customer)<\/li>\n<li>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438)<\/li>\n<li>\u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0447\u0451\u0442\u043a\u043e \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445).<\/li>\n<li>\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0443\u0442\u0435\u043d\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f). \u042d\u0442\u043e <a href=\"http:\/\/en.wikipedia.org\/wiki\/Strategy_pattern\">Strategy pattern<\/a> GoF.<\/li>\n<\/ul>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434 User#authenticate \u0432 UserAuthenticator:  <\/p>\n<pre><code class=\"ruby\">class UserAuthenticator   def initialize(user)     @user = user   end    def authenticate(unencrypted_password)     return false unless @user     if BCrypt::Password.new(@user.password_digest) == unencrypted_password @user     else false      end   end end  <\/code><\/pre>\n<p>  \u0418 SessionsController \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"ruby\">class SessionsController &lt; ApplicationController   def create     user = User.where(email: params[:email]).first     if UserAuthenticator.new(user).authenticate(params[:password])       self.current_user = user redirect_to dashboard_path     else       flash[:alert] = &quot;Login failed.&quot;       render &quot;new&quot;     end   end end  <\/code><\/pre>\n<p>  <\/p>\n<h4>3. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Form Objects<\/h4>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0434\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043b\u043e\u0433\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 Form Object. \u042d\u0442\u043e \u043a\u0443\u0434\u0430 \u0447\u0438\u0449\u0435, \u0447\u0435\u043c <a href=\"http:\/\/api.rubyonrails.org\/classes\/ActiveRecord\/NestedAttributes\/ClassMethods.html\">accepts_nested_attributes_for<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0438\u043c\u0445\u043e, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e \u0443\u0431\u0440\u0430\u0442\u044c. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u043e\u0440\u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u0442 Company \u0438 User:  <\/p>\n<pre><code class=\"ruby\">class Signup include Virtus extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations   attr_reader :user   attr_reader :company   attribute :name, String   attribute :company_name, String   attribute :email, String   validates :email, presence: true   # \u2026 more validations \u2026    # Forms are never themselves persisted   def persisted?     false   end     def save     if valid?       persist!       true     else       false     end   end    private    def persist!     @company = Company.create!(name: company_name)     @user = @company.users.create!(name: name, email: email)   end end <\/code><\/pre>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <a href=\"https:\/\/github.com\/solnic\/virtus\">Virtus<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c, \u043a\u0430\u043a \u0443 ActiveRecord. \u0422\u0430\u043a \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u044f \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"ruby\">class SignupsController &lt; ApplicationController   def create     @signup = Signup.new(params[:signup])     if @signup.save       redirect_to dashboard_path     else       render &quot;new&quot;     end   end end <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u0415\u0441\u043b\u0438 \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0436\u043d\u0430, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 Service Object. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430: \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0440\u0430\u0437\u043c\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f\u043c \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h4>4. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Query Objects<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0443\u0442\u044f\u0436\u0435\u043b\u044f\u044e\u0449\u0438\u0445 \u0432\u0430\u0448\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Query Objects. \u041a\u0430\u0436\u0434\u044b\u0439 Query Object \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Query Object, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0437\u0430\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u044b:  <\/p>\n<pre><code class=\"ruby\">class AbandonedTrialQuery   def initialize(relation = Account.scoped)     @relation = relation   end    def find_each(&block)     @relation. where(plan: nil, invites_count: 0).find_each(&block)   end end  <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 background job \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e\u0447\u0442\u044b:  <\/p>\n<pre><code class=\"ruby\">AbandonedTrialQuery.new.find_each do |account|   account.send_offer_for_support end <\/code><\/pre>\n<p>  ActiveRecord::Relation \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 Rails 3, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043a\u0430\u043a \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 Query Object. \u0418 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e Relation \u0438 Query Object:  <\/p>\n<pre><code class=\"ruby\">old_accounts = Account.where(&quot;created_at &lt; ?&quot;, 1.month.ago) old_abandoned_trials = AbandonedTrialQuery.new(old_accounts) <\/code><\/pre>\n<p>  \u041d\u0435 \u0443\u0432\u043b\u0435\u043a\u0430\u0439\u0442\u0435\u0441\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 N+1 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<h4>5. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 View Objects<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438. \u0421\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0441\u0435\u0431\u044f: \u201c\u0415\u0441\u043b\u0438 \u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0443\u0436\u0435\u043d?\u201d. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u0445\u0435\u043b\u043f\u0435\u0440 \u0438\u043b\u0438 \u0432\u043e View Object.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u044c\u0446\u0435\u0432\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u0432 Code Climate \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0438 \u0432\u0441\u0435\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/codeclimate.com\/github\/rails\/rails\">Rails on Code Climate<\/a>), \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0441\u043d\u044d\u043f\u0448\u043e\u0442\u0435 \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:  <\/p>\n<pre><code class=\"ruby\">class DonutChart   def initialize(snapshot)     @snapshot = snapshot   end    def cache_key    @snapshot.id.to_s   end    def data    # pull data from @snapshot and turn it into a JSON structure   end end <\/code><\/pre>\n<p>  \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0443 \u043e\u0434\u043d\u043e\u043c\u0443 View Object \u0443 \u043c\u0435\u043d\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0448\u0430\u0431\u043b\u043e\u043d ERB(HAML\/SLIM). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0432 Rails \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <a href=\"http:\/\/martinfowler.com\/eaaCatalog\/twoStepView.html\">Two Step View<\/a>.<\/p>\n<h4>6. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Policy Objects<\/h4>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u044e Policy Object. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0443\u044e \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435:  <\/p>\n<pre><code class=\"ruby\">class ActiveUserPolicy   def initialize(user)     @user = user   end    def active?    @user.email_confirmed? && @user.last_login_at &gt; 14.days.ago   end end  <\/code><\/pre>\n<p>  Policy Object \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043f\u043e\u0447\u0442\u0430 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0430 \u0438 \u043e\u043d \u043b\u043e\u0433\u0438\u043d\u0438\u043b\u0441\u044f \u043d\u0435 \u0440\u0430\u043d\u044c\u0448\u0435 \u0447\u0435\u043c \u0434\u0432\u0435 \u043d\u0435\u0434\u0435\u043b\u0438 \u043d\u0430\u0437\u0430\u0434. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Policy Objects \u0434\u043b\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Authorizer, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a \u043a\u0430\u043a\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f.<br \/>  Policy Objects \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 Service Objects, \u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Service Object \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 Policy Object \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 Query Objects, \u043d\u043e Query Objects \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0430 Policy Objects \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043c\u043e\u0434\u0435\u043b\u044c, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u0432 \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<h4>7. \u0412\u044b\u0434\u0435\u043b\u044f\u0439\u0442\u0435 Decorators<\/h4>\n<p>  Decorators \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b: \u043e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0438. Decorators \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u0440\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0438\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0437\u0430\u0433\u0440\u044f\u0437\u043d\u044f\u0435\u0442 \u0435\u0451.<br \/>  \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u0431\u043b\u043e\u0433\u0435, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u0442\u0435\u043d\u0435 Facebook \u0430\u0432\u0442\u043e\u0440\u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u044d\u0442\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Comment. \u041f\u0440\u0438\u0437\u043d\u0430\u043a \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u043e\u0432, \u044d\u0442\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u0445\u0440\u0443\u043f\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0438\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0431\u0438\u0442\u044c \u044d\u0442\u0438 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0438 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<br \/>  \u0412\u043e\u0442 \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e\u0441\u0442\u0438\u043d\u0433\u0430 \u043d\u0430 Facebook \u0432 Decorator:  <\/p>\n<pre><code class=\"ruby\">class FacebookCommentNotifier   def initialize(comment)     @comment = comment   end    def save    @comment.save && post_to_wall   end    private    def post_to_wall     Facebook.post(title: @comment.title, user: @comment.author)   end end  <\/code><\/pre>\n<p>  \u0418 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:  <\/p>\n<pre><code class=\"ruby\">class CommentsController &lt; ApplicationController\u00a0   def create     @comment = FacebookCommentNotifier.new(Comment.new(params[:comment]))     if @comment.save       redirect_to blog_path, notice: &quot;Your comment was posted.&quot;     else       render &quot;new&quot;     end   end end <\/code><\/pre>\n<p>  Decorators \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 Service Objects \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b FacebookCommentNotifier \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b Comment. Ruby \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c <a href=\"http:\/\/robots.thoughtbot.com\/post\/14825364877\/evaluating-alternative-decorator-implementations-in\">\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043b\u0435\u0433\u0447\u0435<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<h4>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 Rails \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u0435\u0445\u043d\u0438\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043c\u043e\u0434\u0435\u043b\u044f\u0445. \u041e\u043d\u0438 \u043d\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 Rails. ActiveRecord \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043d\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043d\u0435\u0451. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u044d\u0442\u0438\u0445 \u0442\u0435\u0445\u043d\u0438\u043a \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0438 \u0432\u0430\u0448\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043d\u0443\u0442 \u043f\u0440\u043e\u0449\u0435.<br \/>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b. \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b Ruby. \u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u0434\u043e \u0432\u0430\u0441 \u0434\u043e\u043d\u0435\u0441\u0442\u0438. \u041d\u0435 \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0438\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/blog.codeclimate.com\/blog\/2012\/10\/17\/7-ways-to-decompose-fat-activerecord-models\/\">\u0442\u0443\u0442<\/a>. \t\t\t \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/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\/158011\/\"> http:\/\/habrahabr.ru\/post\/158011\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0422\u043e\u043b\u0441\u0442\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435. \u041e\u043d\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043d\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Single_responsibility_principle\">Single Responsibility Principle<\/a>(SRP). \u201c\u0412\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u201d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f single responsibility.<br \/>  \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 SRP \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e. \u041d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0434\u0435-\u0444\u0430\u043a\u0442\u043e \u043c\u0435\u0441\u0442\u043e\u043c \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438. \u0418 \u0441\u043f\u0443\u0441\u0442\u044f \u0434\u0432\u0430 \u0433\u043e\u0434\u0430 \u0443 \u043c\u043e\u0434\u0435\u043b\u0438 User \u0431\u043e\u043b\u044c\u0448\u0435 500 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u0438 50 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 public.<br \/>  \u0426\u0435\u043b\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0442\u0443\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0438 \u043c\u043e\u0434\u0443\u043b\u044f\u043c. Fat models, skinny controllers \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0432 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435, \u0442\u0430\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0438 \u0432\u0442\u043e\u0440\u043e\u0439.<\/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-158011","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/158011","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=158011"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/158011\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}