{"id":280596,"date":"2016-11-08T11:20:11","date_gmt":"2016-11-08T08:20:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280596"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280596","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0432\u0438\u0436\u043a\u0430 \u0434\u043b\u044f \u0431\u043b\u043e\u0433\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Phoenix \u0438 Elixir \/ \u0427\u0430\u0441\u0442\u044c 2. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/bab\/544\/80a\/bab54480ad8d41418519f4b2d5a79a71.png\"\/><\/p>\n<p>  \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u00ab<i>Elixir \u0438 Phoenix \u2014 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0443\u0434\u0430 \u0434\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430. \u0423\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0421\u0430\u0439\u0442\u044b \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u044b\u0435 \u0438\u0433\u0440\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0442\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u043e\u0441\u043b\u0443\u0436\u0430\u0442 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0441\u043b\u0443\u0436\u0431\u0443. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0438\u0437 11 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0424\u0435\u043d\u0438\u043a\u0441 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a. \u041d\u043e \u043d\u0435 \u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u043a\u0443\u043a\u0441\u0438\u0442\u044c\u0441\u044f, \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0431\u0443\u0434\u044f\u0442 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u042d\u043b\u0438\u043a\u0441\u0438\u0440 \u043b\u0438\u0431\u043e \u0441\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u0431\u043b\u043e\u0433\u0430, \u0447\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435 \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e. \u041f\u0440\u043e\u0448\u0443 \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u0437\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0451\u0442\u043a\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043b\u0438\u0431\u043e \u0438\u0434\u0442\u0438 \u043d\u0430 \u043e\u043f\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435!<\/i>\u00bb<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430:  <\/p>\n<ul>\n<li><b>Elixir<\/b>: v1.3.1<\/li>\n<li><b>Phoenix<\/b>: v1.2.0<\/li>\n<li><b>Ecto<\/b>: v2.0.2<\/li>\n<li><b>Comeonin<\/b>: v2.5.2<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0430\u0433\u0438<\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u0443 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <s><i>\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438<\/i><\/s> \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 Elixir\/Phoenix. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043c\u0435\u043d\u044f, \u0442\u043e \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0430\u044f \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0443\u0434\u043e\u0440\u0430\u0436\u0438\u0442 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u043f\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0445\u043e\u0434\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b, \u044f \u0432\u044b\u043b\u0438\u043b \u0434\u043b\u044f \u0432\u0430\u0441 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/Diamond\/pxblog\/tree\/part_1\">\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043d\u0430 Github<\/a>.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0431\u0430\u0433 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:4000\/sessions\/new\">http:\/\/localhost:4000\/sessions\/new<\/a> \u0438 \u043d\u0430\u0436\u0430\u0432 \u043a\u043d\u043e\u043f\u043a\u0443 <b>Submit<\/b>. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430:<\/p>\n<pre><code class=\"bash\">nil given for :username, comparison with nil is forbidden as it always evaluates to false. Pass a full query expression and use is_nil\/1 instead. <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>create<\/b> \u0432 <b>SessionController<\/b> \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0432 \u0447\u0451\u043c \u0434\u0435\u043b\u043e.<\/p>\n<pre><code class=\"ruby\">def create(conn, %{&quot;user&quot; =&gt; user_params}) do   user = Repo.get_by(User, username: user_params[&quot;username&quot;])   user   |&gt; sign_in(user_params[&quot;password&quot;], conn) end <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0432\u043c\u0435\u0441\u0442\u043e <b>username<\/b> \u0441\u0442\u0440\u043e\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e), \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u044d\u0442\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0445\u0440\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 (<i>guard clause<\/i>) \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (<i>pattern matching<\/i>). \u0417\u0430\u043c\u0435\u043d\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>create<\/b> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<\/p>\n<pre><code class=\"ruby\">def create(conn, %{&quot;user&quot; =&gt; %{&quot;username&quot; =&gt; username, &quot;password&quot; =&gt; password}}) when not is_nil(username) and not is_nil(password) do   user = Repo.get_by(User, username: username)   sign_in(user, password, conn) end  def create(conn, _) do   failed_login(conn) end <\/code><\/pre>\n<p>  \u041c\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <b>params<\/b> \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>create<\/b> \u043d\u0438\u0436\u043d\u0438\u043c \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u043d\u0438\u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>failed_login<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0439. \u0412 \u0444\u0430\u0439\u043b\u0435 <b>web\/controllers\/session_controller.ex<\/b> \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043c\u043f\u043e\u0440\u0442 <b>Comeonin<\/b>:<\/p>\n<pre><code class=\"ruby\">import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0] <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <b>dummy_checkpw()<\/b> \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0430\u0442\u0430\u043a\u0443 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>failed_login<\/b>:<\/p>\n<pre><code class=\"ruby\">defp failed_login(conn) do   dummy_checkpw()   conn   |&gt; put_session(:current_user, nil)   |&gt; put_flash(:error, &quot;Invalid username\/password combination!&quot;)   |&gt; redirect(to: page_path(conn, :index))   |&gt; halt() end <\/code><\/pre>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 <b>dummy_checkpw()<\/b> \u0432\u0432\u0435\u0440\u0445\u0443! \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0435\u0441\u0441\u0438\u044e <b>current_user<\/b>, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c flash-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0433\u043e\u0432\u043e\u0440\u044f\u0449\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0432\u0432\u043e\u0434\u0435 \u043b\u043e\u0433\u0438\u043d\u0430 \u0438 \u043f\u0430\u0440\u043e\u043b\u044f \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u041f\u043e\u0434 \u043a\u043e\u043d\u0435\u0446 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>halt<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0443\u043c\u043d\u043e\u0439 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0434\u0432\u043e\u0439\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0430. \u0418 \u0437\u0430\u0442\u0435\u043c \u0432\u0435\u0441\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u043d\u0430\u0448\u0435\u0439 \u043d\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"ruby\">defp sign_in(user, _password, conn) when is_nil(user) do   failed_login(conn) end defp sign_in(user, password, conn) do   if checkpw(password, user.password_digest) do     conn     |&gt; put_session(:current_user, %{id: user.id, username: user.username})     |&gt; put_flash(:info, &quot;Sign in successful!&quot;)     |&gt; redirect(to: page_path(conn, :index))   else     failed_login(conn)   end end <\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0431\u0430\u0433\u0430\u0445 \u0441\u043e \u0432\u0445\u043e\u0434\u043e\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438 \u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>posts<\/b> \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>users<\/b>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0447\u0435\u0440\u0435\u0437 <b>Ecto-\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/b> \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"bash\">$ mix ecto.gen.migration add_user_id_to_posts <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">Compiling 1 file (.ex) * creating priv\/repo\/migrations * creating priv\/repo\/migrations\/20160720211140_add_user_id_to_posts.exs <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0432 \u043d\u0451\u043c \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u043c. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>change<\/b> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"ruby\">def change do   alter table(:posts) do     add :user_id, references(:users)   end   create index(:posts, [:user_id]) end <\/code><\/pre>\n<p>  \u042d\u0442\u0438\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 <b>user_id<\/b>, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0443\u044e\u0441\u044f \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u043d\u0435\u0451. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>mix ecto.migrate<\/code> \u0438 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h2>\u0421\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u044b \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b <b>web\/models\/post.ex<\/b> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c <b>User<\/b>. \u0412\u043d\u0443\u0442\u0440\u044c \u0441\u0445\u0435\u043c\u044b <b>posts<\/b> \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"ruby\">belongs_to :user, Pxblog.User <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u043e\u0434\u0435\u043b\u044c <b>User<\/b> \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c <b>Post<\/b>. \u0412\u043d\u0443\u0442\u0440\u044c \u0441\u0445\u0435\u043c\u044b <b>users<\/b> \u0432 \u0444\u0430\u0439\u043b\u0435 <b>web\/models\/user.ex<\/b> \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"ruby\">has_many :posts, Pxblog.Post <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <b>Posts<\/b> \u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<h2>\u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0443\u0442\u0438<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u043e\u0443\u0442\u0435\u0440\u0430, \u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u043e\u0441\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b <b>web\/router.ex<\/b> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u043f\u0443\u0442\u0438 <b>\/users<\/b> \u0438 <b>\/posts<\/b> \u043d\u0430:<\/p>\n<pre><code class=\"ruby\">resources &quot;\/users&quot;, UserController do   resources &quot;\/posts&quot;, PostController end <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>mix phoenix.routes<\/code> \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443. \u042d\u0442\u043e \u043d\u043e\u0440\u043c\u0430! \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0443\u0442\u0435\u0439, \u0442\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0445\u0435\u043b\u043f\u0435\u0440 <b>post_path<\/b>, \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <b>user_post_path<\/b> \u0438 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441. \u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0445\u0435\u043b\u043f\u0435\u0440\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0443\u0442\u044f\u043c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (\u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0441\u0442\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f).<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0445\u0435\u043b\u043f\u0435\u0440 <b>post_path<\/b>, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c:<\/p>\n<pre><code class=\"ruby\">post_path(conn, :show, post) <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442 <b>conn<\/b> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0430\u0442\u043e\u043c <b>:show<\/b> \u2014 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0441\u0441\u044b\u043b\u0430\u0435\u043c\u0441\u044f, \u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043c\u044b \u043b\u0438\u0431\u043e \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043b\u0438\u0431\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041e\u0442\u0441\u044e\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">post_path(conn, :show, 1) <\/code><\/pre>\n<p>  \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441, \u0445\u0435\u043b\u043f\u0435\u0440\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 routes. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435:<\/p>\n<pre><code class=\"ruby\">user_post_path(conn, :show, user, post) <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0441\u0443\u0440\u0441, \u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0438\u0434\u0451\u0442 \u0441\u043b\u0435\u0434\u043e\u043c. <\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u0433. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b <b>web\/controllers\/post_controller.ex<\/b> \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0432\u0435\u0440\u0445\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u044b\u0437\u043e\u0432 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043b\u0430\u0433\u0430:<\/p>\n<pre><code class=\"ruby\">plug :assign_user <\/code><\/pre>\n<p>  \u0410 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u044b \u0435\u0433\u043e \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"ruby\">defp assign_user(conn, _opts) do   case conn.params do     %{&quot;user_id&quot; =&gt; user_id} -&gt;       user = Repo.get(Pxblog.User, user_id)       assign(conn, :user, user)     _ -&gt;       conn   end end <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u0442\u0435\u043c \u0432\u0435\u0437\u0434\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u043c <b>post_path<\/b> \u043d\u0430 <b>user_post_path<\/b>:<\/p>\n<pre><code class=\"ruby\">def create(conn, %{&quot;post&quot; =&gt; post_params}) do  changeset = Post.changeset(%Post{}, post_params)   case Repo.insert(changeset) do     {:ok, _post} -&gt;       conn       |&gt; put_flash(:info, &quot;Post created successfully.&quot;)       |&gt; redirect(to: user_post_path(conn, :index, conn.assigns[:user]))     {:error, changeset} -&gt;       render(conn, &quot;new.html&quot;, changeset: changeset)   end end  def update(conn, %{&quot;id&quot; =&gt; id, &quot;post&quot; =&gt; post_params}) do   post = Repo.get!(Post, id)   changeset = Post.changeset(post, post_params)   case Repo.update(changeset) do     {:ok, post} -&gt;       conn       |&gt; put_flash(:info, &quot;Post updated successfully.&quot;)       |&gt; redirect(to: user_post_path(conn, :show, conn.assigns[:user], post))     {:error, changeset} -&gt;       render(conn, &quot;edit.html&quot;, post: post, changeset: changeset)   end end  def delete(conn, %{&quot;id&quot; =&gt; id}) do   post = Repo.get!(Post, id)   # \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c delete! (\u0441 \u0432\u043e\u0441\u043a\u043b\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u043a\u043e\u043c), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c   # \u0447\u0442\u043e \u043a\u043e\u0434 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430).   Repo.delete!(post)   conn   |&gt; put_flash(:info, &quot;Post deleted successfully.&quot;)   |&gt; redirect(to: user_post_path(conn, :index, conn.assigns[:user])) end <\/code><\/pre>\n<p>  <\/p>\n<h2>\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u044b<\/h2>\n<p>  \u041d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b \u00ab\u0432\u044b\u043f\u043b\u0451\u0432\u044b\u0432\u0430\u0442\u044c\u00bb \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0434 \u043d\u0430\u0448\u0438\u043c\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438. \u041c\u044b \u043f\u043e\u0448\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0439 \u0434\u043e\u0440\u043e\u0433\u043e\u0439, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u043f\u043b\u0430\u0433, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>assign<\/b> \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u0445\u0435\u043b\u043f\u0435\u0440 post_path \u043d\u0430 user_post_path \u0438 \u0443\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412 \u0444\u0430\u0439\u043b\u0435 <b>web\/templates\/post\/index.html.eex<\/b> \u043d\u0430\u043f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"html\">&lt;h2&gt;Listing posts&lt;\/h2&gt; &lt;table class=&quot;table&quot;&gt;   &lt;thead&gt;     &lt;tr&gt;       &lt;th&gt;Title&lt;\/th&gt;       &lt;th&gt;Body&lt;\/th&gt; &lt;th&gt;&lt;\/th&gt;     &lt;\/tr&gt;   &lt;\/thead&gt;   &lt;tbody&gt; &lt;%= for post &lt;- @posts do %&gt;     &lt;tr&gt;       &lt;td&gt;&lt;%= post.title %&gt;&lt;\/td&gt;       &lt;td&gt;&lt;%= post.body %&gt;&lt;\/td&gt; &lt;td class=&quot;text-right&quot;&gt;         &lt;%= link &quot;Show&quot;, to: user_post_path(@conn, :show, @user, post), class: &quot;btn btn-default btn-xs&quot; %&gt;         &lt;%= link &quot;Edit&quot;, to: user_post_path(@conn, :edit, @user, post), class: &quot;btn btn-default btn-xs&quot; %&gt;         &lt;%= link &quot;Delete&quot;, to: user_post_path(@conn, :delete, @user, post), method: :delete, data: [confirm: &quot;Are you sure?&quot;], class: &quot;btn btn-danger btn-xs&quot; %&gt;       &lt;\/td&gt;     &lt;\/tr&gt; &lt;% end %&gt;   &lt;\/tbody&gt; &lt;\/table&gt; &lt;%= link &quot;New post&quot;, to: user_post_path(@conn, :new, @user) %&gt; <\/code><\/pre>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 <b>web\/templates\/post\/show.html.eex<\/b>:<\/p>\n<pre><code class=\"html\">&lt;h2&gt;Show post&lt;\/h2&gt; &lt;ul&gt;   &lt;li&gt;     &lt;strong&gt;Title:&lt;\/strong&gt;     &lt;%= @post.title %&gt;   &lt;\/li&gt;   &lt;li&gt;     &lt;strong&gt;Body:&lt;\/strong&gt;     &lt;%= @post.body %&gt;   &lt;\/li&gt; &lt;\/ul&gt; &lt;%= link &quot;Edit&quot;, to: user_post_path(@conn, :edit, @user, @post) %&gt; &lt;%= link &quot;Back&quot;, to: user_post_path(@conn, :index, @user) %&gt; <\/code><\/pre>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 <b>web\/templates\/post\/new.html.eex<\/b>:<\/p>\n<pre><code class=\"html\">&lt;h2&gt;New post&lt;\/h2&gt; &lt;%= render &quot;form.html&quot;, changeset: @changeset,                         action: user_post_path(@conn, :create, @user) %&gt; &lt;%= link &quot;Back&quot;, to: user_post_path(@conn, :index, @user) %&gt; <\/code><\/pre>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 <b>web\/templates\/post\/edit.html.eex<\/b>:<\/p>\n<pre><code class=\"html\">&lt;h2&gt;Edit post&lt;\/h2&gt; &lt;%= render &quot;form.html&quot;, changeset: @changeset,                         action: user_post_path(@conn, :update, @user, @post) %&gt; &lt;%= link &quot;Back&quot;, to: user_post_path(@conn, :index, @user) %&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c <code>mix phoenix.routes<\/code>, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043f\u0443\u0442\u0435\u0439 \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e!<\/p>\n<pre><code class=\"bash\">Compiling 14 files (.ex)      page_path  GET     \/                               Pxblog.PageController :index      user_path  GET     \/users                          Pxblog.UserController :index      user_path  GET     \/users\/:id\/edit                 Pxblog.UserController :edit      user_path  GET     \/users\/new                      Pxblog.UserController :new      user_path  GET     \/users\/:id                      Pxblog.UserController :show      user_path  POST    \/users                          Pxblog.UserController :create      user_path  PATCH   \/users\/:id                      Pxblog.UserController :update                 PUT     \/users\/:id                      Pxblog.UserController :update      user_path  DELETE  \/users\/:id                      Pxblog.UserController :delete user_post_path  GET     \/users\/:user_id\/posts           Pxblog.PostController :index user_post_path  GET     \/users\/:user_id\/posts\/:id\/edit  Pxblog.PostController :edit user_post_path  GET     \/users\/:user_id\/posts\/new       Pxblog.PostController :new user_post_path  GET     \/users\/:user_id\/posts\/:id       Pxblog.PostController :show user_post_path  POST    \/users\/:user_id\/posts           Pxblog.PostController :create user_post_path  PATCH   \/users\/:user_id\/posts\/:id       Pxblog.PostController :update                 PUT     \/users\/:user_id\/posts\/:id       Pxblog.PostController :update user_post_path  DELETE  \/users\/:user_id\/posts\/:id       Pxblog.PostController :delete   session_path  GET     \/sessions\/new                   Pxblog.SessionController :new   session_path  POST    \/sessions                       Pxblog.SessionController :create   session_path  DELETE  \/sessions\/:id                   Pxblog.SessionController :delete <\/code><\/pre>\n<p>  <\/p>\n<h2>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443<\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u2014 \u044d\u0442\u043e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>iex -S mix<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432\/\u0430\u043b\u0438\u0430\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 iex \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <b>.iex.exs<\/b> (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u0447\u043a\u0443 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430) \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre><code class=\"ruby\">import Ecto.Query alias Pxblog.User alias Pxblog.Post alias Pxblog.Repo import Ecto <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 iex \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e:<\/p>\n<pre><code class=\"ruby\">iex(1)&gt; import Ecto.Query nil iex(2)&gt; alias Pxblog.User nil iex(3)&gt; alias Pxblog.Post nil iex(4)&gt; alias Pxblog.Repo nil iex(5)&gt; import Ecto nil <\/code><\/pre>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0435\u0433\u043e. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c:<\/p>\n<pre><code class=\"ruby\">iex(8)&gt; user = Repo.get(User, 1)     [debug] SELECT u0.&quot;id&quot;, u0.&quot;username&quot;, u0.&quot;email&quot;, u0.&quot;password_digest&quot;, u0.&quot;inserted_at&quot;, u0.&quot;updated_at&quot; FROM &quot;users&quot; AS u0 WHERE (u0.&quot;id&quot; = $1) [1] OK query=8.2ms     %Pxblog.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded&gt;, email: &quot;test&quot;, id: 1,      inserted_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, password: nil,      password_confirmation: nil,      password_digest: &quot;$2b$12$pV\/XBBCRl0RQhadQd9Y4mevOy5y0j4bCC\/LjGgx7VJMosRdwme22a&quot;,      posts: #Ecto.Association.NotLoaded&lt;association :posts is not loaded&gt;,      updated_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, username: &quot;test&quot;} iex(10)&gt; Repo.all(assoc(user, :posts))     [debug] SELECT p0.&quot;id&quot;, p0.&quot;title&quot;, p0.&quot;body&quot;, p0.&quot;user_id&quot;, p0.&quot;inserted_at&quot;, p0.&quot;updated_at&quot; FROM &quot;posts&quot; AS p0 WHERE (p0.&quot;user_id&quot; IN ($1)) [1] OK query=3.5ms     [] <\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>assoc<\/b> \u0438\u0437 <b>Ecto<\/b>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0441\u0442\u044b \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"ruby\">iex(14)&gt; Repo.all from p in Post, ...(14)&gt;          join: u in assoc(p, :user), ...(14)&gt;          select: p [debug] SELECT p0.&quot;id&quot;, p0.&quot;title&quot;, p0.&quot;body&quot;, p0.&quot;user_id&quot;, p0.&quot;inserted_at&quot;, p0.&quot;updated_at&quot; FROM &quot;posts&quot; AS p0 INNER JOIN &quot;users&quot; AS u1 ON u1.&quot;id&quot; = p0.&quot;user_id&quot; [] OK query=0.9ms <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 inner join \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c SQL, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u00ab\u0437\u0430 \u043a\u0443\u043b\u0438\u0441\u0430\u043c\u0438\u00bb \u0432\u0441\u0435\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u043a\u043e\u0434\u043e\u043c, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<br \/>  \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>preload<\/b> \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u043f\u043e\u0441\u0442\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"ruby\">iex(18)&gt; Repo.all(from u in User, preload: [:posts]) [debug] SELECT u0.&quot;id&quot;, u0.&quot;username&quot;, u0.&quot;email&quot;, u0.&quot;password_digest&quot;, u0.&quot;inserted_at&quot;, u0.&quot;updated_at&quot; FROM &quot;users&quot; AS u0 [] OK query=0.9ms [debug] SELECT p0.&quot;id&quot;, p0.&quot;title&quot;, p0.&quot;body&quot;, p0.&quot;user_id&quot;, p0.&quot;inserted_at&quot;, p0.&quot;updated_at&quot; FROM &quot;posts&quot; AS p0 WHERE (p0.&quot;user_id&quot; IN ($1)) ORDER BY p0.&quot;user_id&quot; [1] OK query=0.8ms iex(20)&gt; Repo.all(from p in Post, preload: [:user]) [debug] SELECT p0.&quot;id&quot;, p0.&quot;title&quot;, p0.&quot;body&quot;, p0.&quot;user_id&quot;, p0.&quot;inserted_at&quot;, p0.&quot;updated_at&quot; FROM &quot;posts&quot; AS p0 [] OK query=0.8ms [] <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. \u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Ecto \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <b>build_assoc<\/b>. \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e, \u0438 \u0432\u0442\u043e\u0440\u044b\u043c \u2014 \u0441\u0430\u043c\u0443 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0430\u0442\u043e\u043c\u0430.<\/p>\n<pre><code class=\"ruby\">iex(1)&gt; user = Repo.get(User, 1) iex(2)&gt; post = build_assoc(user, :posts, %{title: &quot;Test Title&quot;, body: &quot;Test Body&quot;}) iex(3)&gt; Repo.insert(post) iex(4)&gt; posts = Repo.all(from p in Post, preload: [:user]) <\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"ruby\">iex(4)&gt; posts = Repo.all(from p in Post, preload: [:user]) [debug] SELECT p0.&quot;id&quot;, p0.&quot;title&quot;, p0.&quot;body&quot;, p0.&quot;user_id&quot;, p0.&quot;inserted_at&quot;, p0.&quot;updated_at&quot; FROM &quot;posts&quot; AS p0 [] OK query=0.7ms [debug] SELECT u0.&quot;id&quot;, u0.&quot;username&quot;, u0.&quot;email&quot;, u0.&quot;password_digest&quot;, u0.&quot;inserted_at&quot;, u0.&quot;updated_at&quot; FROM &quot;users&quot; AS u0 WHERE (u0.&quot;id&quot; IN ($1)) [1] OK query=0.7ms [%Pxblog.Post{__meta__: #Ecto.Schema.Metadata&lt;:loaded&gt;, body: &quot;Test Body&quot;,   id: 1, inserted_at: #Ecto.DateTime&lt;2015-10-06T18:06:20Z&gt;, title: &quot;Test Title&quot;,   updated_at: #Ecto.DateTime&lt;2015-10-06T18:06:20Z&gt;,   user: %Pxblog.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded&gt;, email: &quot;test&quot;,    id: 1, inserted_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, password: nil,    password_confirmation: nil,    password_digest: &quot;$2b$12$pV\/XBBCRl0RQhadQd9Y4mevOy5y0j4bCC\/LjGgx7VJMosRdwme22a&quot;,    posts: #Ecto.Association.NotLoaded&lt;association :posts is not loaded&gt;,    updated_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, username: &quot;test&quot;},   user_id: 1}] <\/code><\/pre>\n<p>  \u0418 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"ruby\">iex(5)&gt; post = List.first posts %Pxblog.Post{__meta__: #Ecto.Schema.Metadata&lt;:loaded&gt;, body: &quot;Test Body&quot;, id: 1,  inserted_at: #Ecto.DateTime&lt;2015-10-06T18:06:20Z&gt;, title: &quot;Test Title&quot;,  updated_at: #Ecto.DateTime&lt;2015-10-06T18:06:20Z&gt;,  user: %Pxblog.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded&gt;, email: &quot;test&quot;,   id: 1, inserted_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, password: nil,   password_confirmation: nil,   password_digest: &quot;$2b$12$pV\/XBBCRl0RQhadQd9Y4mevOy5y0j4bCC\/LjGgx7VJMosRdwme22a&quot;,   posts: #Ecto.Association.NotLoaded&lt;association :posts is not loaded&gt;,   updated_at: #Ecto.DateTime&lt;2015-10-06T17:47:07Z&gt;, username: &quot;test&quot;},  user_id: 1} iex(6)&gt; post.title &quot;Test Title&quot; iex(7)&gt; post.user.username &quot;test&quot; <\/code><\/pre>\n<p>  \u041a\u0440\u0443\u0442\u043e! \u041d\u0430\u0448 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u043b\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443 (\u0444\u0430\u0439\u043b <b>web\/controllers\/post_controller.ex<\/b>) \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434. \u0412 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 <b>index<\/b> \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0421 \u043d\u0435\u0433\u043e \u0438 \u043d\u0430\u0447\u043d\u0451\u043c:<\/p>\n<pre><code class=\"ruby\">def index(conn, _params) do   posts = Repo.all(assoc(conn.assigns[:user], :posts))   render(conn, &quot;index.html&quot;, posts: posts) end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f! \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u043e\u0445\u0438\u043c UX, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u0432 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0430\u0448 \u043f\u043b\u0430\u0433 <b>assign_user<\/b>:<\/p>\n<pre><code class=\"ruby\">defp assign_user(conn, _opts) do   case conn.params do     %{&quot;user_id&quot; =&gt; user_id} -&gt;       case Repo.get(Pxblog.User, user_id) do         nil  -&gt; invalid_user(conn)         user -&gt; assign(conn, :user, user)       end     _ -&gt; invalid_user(conn)   end end  defp invalid_user(conn) do   conn   |&gt; put_flash(:error, &quot;Invalid user!&quot;)   |&gt; redirect(to: page_path(conn, :index))   |&gt; halt end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u0438\u043b\u043e\u0435 flash-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0431\u0443\u0434\u0435\u043c \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u044b \u043d\u0430 <b>page_path<\/b>. \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 <b>new<\/b>:<\/p>\n<pre><code class=\"ruby\">def new(conn, _params) do   changeset =     conn.assigns[:user]     |&gt; build_assoc(:posts)     |&gt; Post.changeset()   render(conn, &quot;new.html&quot;, changeset: changeset) end <\/code><\/pre>\n<p>  \u041c\u044b \u0431\u0435\u0440\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u044c <b>user<\/b>, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0435\u0451 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>build_assoc<\/b>, \u0433\u043e\u0432\u043e\u0440\u044f \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u0442, \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u043f\u0443\u0441\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>Post.changeset<\/b>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e \u0440\u0435\u0432\u0438\u0437\u0438\u044e. \u041c\u044b \u043f\u043e\u0439\u0434\u0451\u043c \u0442\u0435\u043c \u0436\u0435 \u043f\u0443\u0442\u0451\u043c \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 create (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f <b>post_params<\/b>):<\/p>\n<pre><code class=\"ruby\">def create(conn, %{&quot;post&quot; =&gt; post_params}) do   changeset =     conn.assigns[:user]     |&gt; build_assoc(:posts)     |&gt; Post.changeset(post_params)   case Repo.insert(changeset) do     {:ok, _post} -&gt;       conn       |&gt; put_flash(:info, &quot;Post created successfully.&quot;)       |&gt; redirect(to: user_post_path(conn, :index, conn.assigns[:user]))     {:error, changeset} -&gt;       render(conn, &quot;new.html&quot;, changeset: changeset)   end end <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <b>show<\/b>, <b>edit<\/b>, <b>update<\/b> \u0438 <b>delete<\/b>:<\/p>\n<pre><code class=\"ruby\">def show(conn, %{&quot;id&quot; =&gt; id}) do   post = Repo.get!(assoc(conn.assigns[:user], :posts), id)   render(conn, &quot;show.html&quot;, post: post) end  def edit(conn, %{&quot;id&quot; =&gt; id}) do   post = Repo.get!(assoc(conn.assigns[:user], :posts), id)   changeset = Post.changeset(post)   render(conn, &quot;edit.html&quot;, post: post, changeset: changeset) end  def update(conn, %{&quot;id&quot; =&gt; id, &quot;post&quot; =&gt; post_params}) do   post = Repo.get!(assoc(conn.assigns[:user], :posts), id)   changeset = Post.changeset(post, post_params)   case Repo.update(changeset) do     {:ok, post} -&gt;       conn       |&gt; put_flash(:info, &quot;Post updated successfully.&quot;)       |&gt; redirect(to: user_post_path(conn, :show, conn.assigns[:user], post))     {:error, changeset} -&gt;       render(conn, &quot;edit.html&quot;, post: post, changeset: changeset)   end end  def delete(conn, %{&quot;id&quot; =&gt; id}) do   post = Repo.get!(assoc(conn.assigns[:user], :posts), id)   # \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c delete! (\u0441 \u0432\u043e\u0441\u043a\u043b\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u043a\u043e\u043c), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c   # \u0447\u0442\u043e \u043e\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430).   Repo.delete!(post)   conn   |&gt; put_flash(:info, &quot;Post deleted successfully.&quot;)   |&gt; redirect(to: user_post_path(conn, :index, conn.assigns[:user])) end <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u0432\u0441\u0435\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0417\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u2026 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u0434\u0430\u043b\u0438\u0442\u044c\/\u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0441\u0442 \u043f\u043e\u0434 \u043b\u044e\u0431\u044b\u043c \u044e\u0437\u0435\u0440\u043e\u043c, \u043a\u0430\u043a\u0438\u043c \u0437\u0430\u0445\u043e\u0447\u0435\u0442!<\/p>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438<\/h2>\n<p>  \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u0441 \u0442\u0430\u043a\u043e\u0439 \u0434\u044b\u0440\u043e\u0439 \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u043b\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043a\u043e\u043d\u0435\u0446 \u0444\u0430\u0439\u043b\u0430 <b>web\/controllers\/post_controller.ex<\/b>:<\/p>\n<pre><code class=\"ruby\">defp authorize_user(conn, _opts) do     user = get_session(conn, :current_user)     if user && Integer.to_string(user.id) == conn.params[&quot;user_id&quot;] do       conn     else       conn       |&gt; put_flash(:error, &quot;You are not authorized to modify that post!&quot;)       |&gt; redirect(to: page_path(conn, :index))       |&gt; halt()     end   end <\/code><\/pre>\n<p>  \u0410 \u0432 \u0441\u0430\u043c\u043e\u043c \u0432\u0435\u0440\u0445\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u044b\u0437\u043e\u0432 \u043f\u043b\u0430\u0433\u0430:<\/p>\n<pre><code class=\"ruby\">plug :authorize_user when action in [:new, :create, :update, :edit, :delete] <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c! \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0441\u0442\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0438\u043c\u0438. \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u2014 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u0442\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u0438 \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c <b>mix test<\/b>, \u0447\u0442\u043e\u0431\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"bash\">** (CompileError) test\/controllers\/post_controller_test.exs:14: function post_path\/2 undefined     (stdlib) lists.erl:1337: :lists.foreach\/2     (stdlib) erl_eval.erl:669: :erl_eval.do_apply\/6     (elixir) lib\/code.ex:363: Code.require_file\/2     (elixir) lib\/kernel\/parallel_require.ex:50: anonymous fn\/4 in Kernel.ParallelRequire.spawn_requires\/5 <\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <b>post_path<\/b> \u043d\u0430 <b>user_post_path<\/b> \u0441\u043d\u043e\u0432\u0430. \u0418 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0434\u0438\u043a\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0432 \u0444\u0430\u0439\u043b <b>test\/controllers\/post_controller_text.exs<\/b>:<\/p>\n<pre><code class=\"ruby\">alias Pxblog.User  setup do   {:ok, user} = create_user   conn = build_conn()   |&gt; login_user(user)   {:ok, conn: conn, user: user} end  defp create_user do   User.changeset(%User{}, %{email: &quot;test@test.com&quot;, username: &quot;test&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})   |&gt; Repo.insert end  defp login_user(conn, user) do   post conn, session_path(conn, :create), user: %{username: user.username, password: user.password} end <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0441\u0435\u0433\u043e. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>create_user<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0435\u043b\u043f\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u0438\u043c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <b>create_user<\/b> \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 <b>Repo<\/b>, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c <b>{:ok, user}<\/b> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>conn = build_conn()<\/b>, \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <b>conn<\/b> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>login_user<\/b>. \u042d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u043e\u0441\u0442\u044b \u0441 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0432\u0445\u043e\u0434\u0430, \u0442. \u043a. \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043f\u043e\u0441\u0442\u0430\u043c\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <b>conn<\/b> \u0438 \u0442\u0430\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u0441\u043e\u0431\u043e\u0439 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442. \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e, \u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u043c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <b>:ok<\/b> \u0438 <b>:conn<\/b>, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0437\u0430\u043f\u0438\u0441\u044c <b>:user<\/b> \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u0438\u043c:<\/p>\n<pre><code class=\"ruby\">test &quot;lists all entries on index&quot;, %{conn: conn, user: user} do   conn = get conn, user_post_path(conn, :index, user)   assert html_response(conn, 200) =~ &quot;Listing posts&quot; end <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 <b>test<\/b>, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043f\u043e\u043c\u0438\u043c\u043e \u043a\u043b\u044e\u0447\u0430 <b>:conn<\/b>, \u0442\u0430\u043a\u0436\u0435 \u0438 \u043a\u043b\u044e\u0447 <b>:user<\/b>. \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043b\u044e\u0447 <b>:user<\/b>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u0431\u043b\u043e\u043a\u0435 <b>setup<\/b>. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u0445\u0435\u043b\u043f\u0435\u0440\u0430 <b>post_path<\/b> \u043d\u0430 <b>user_post_path<\/b> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0435\u0433\u0430, \u043b\u0438\u0431\u043e \u0443\u043a\u0430\u0437\u0430\u0432 \u043d\u043e\u043c\u0435\u0440 \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"bash\">$ mix test test\/controller\/post_controller_test.exs:[line number] <\/code><\/pre>\n<p>  \u041d\u0430\u0448 \u0442\u0435\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0437\u0435\u043b\u0435\u043d\u0435\u0442\u044c! \u0412\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u0443\u0441\u043e\u043a:<\/p>\n<pre><code class=\"ruby\">test &quot;renders form for new resources&quot;, %{conn: conn, user: user} do   conn = get conn, user_post_path(conn, :new, user)   assert html_response(conn, 200) =~ &quot;New post&quot; end <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u043a\u0440\u043e\u043c\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 <b>setup<\/b> \u0438 \u043f\u0443\u0442\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<pre><code class=\"ruby\">test &quot;creates resource and redirects when data is valid&quot;, %{conn: conn, user: user} do   conn = post conn, user_post_path(conn, :create, user), post: @valid_attrs   assert redirected_to(conn) == user_post_path(conn, :index, user)   assert Repo.get_by(assoc(user, :posts), @valid_attrs) end <\/code><\/pre>\n<p>  \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u0442, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b <b>post_path<\/b>.<\/p>\n<pre><code class=\"ruby\">test &quot;does not create resource and renders errors when data is invalid&quot;, %{conn: conn, user: user} do   conn = post conn, user_post_path(conn, :create, user), post: @invalid_attrs   assert html_response(conn, 200) =~ &quot;New post&quot; end <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043b\u0435\u0433\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442. \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u0441\u043d\u043e\u0432\u0430, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c\/\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u044b, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u0430 <b>\u201cshows chosen resource\u201d<\/b>:<\/p>\n<pre><code class=\"ruby\">test &quot;shows chosen resource&quot;, %{conn: conn, user: user} do   post = build_post(user)   conn = get conn, user_post_path(conn, :show, user, post)   assert html_response(conn, 200) =~ &quot;Show post&quot; end <\/code><\/pre>\n<p>  \u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u043f\u043e\u0441\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e <code>Repo.insert! %Post{}<\/code>. \u042d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0445 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0435\u0439. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u0445, \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0445\u0435\u043b\u043f\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<pre><code class=\"ruby\">defp build_post(user) do   changeset =     user     |&gt; build_assoc(:posts)     |&gt; Post.changeset(@valid_attrs)   Repo.insert!(changeset) end <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0451 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <b>Repo.insert!<\/b> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 <b>{:ok, model}<\/b>, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0430\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c!<\/p>\n<p>  \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0442\u0435\u0441\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u043b\u0438. \u042f \u0445\u043e\u0447\u0443 \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0442\u0435\u0441\u0442\u043e\u0432, \u0430 \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043d\u0435 \u043d\u0430\u0447\u043d\u0443\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c.<\/p>\n<pre><code class=\"ruby\">test &quot;renders page not found when id is nonexistent&quot;, %{conn: conn, user: user} do     assert_raise Ecto.NoResultsError, fn -&gt;       get conn, user_post_path(conn, :show, user, -1)     end   end    test &quot;renders form for editing chosen resource&quot;, %{conn: conn, user: user} do     post = build_post(user)     conn = get conn, user_post_path(conn, :edit, user, post)     assert html_response(conn, 200) =~ &quot;Edit post&quot;   end    test &quot;updates chosen resource and redirects when data is valid&quot;, %{conn: conn, user: user} do     post = build_post(user)     conn = put conn, user_post_path(conn, :update, user, post), post: @valid_attrs     assert redirected_to(conn) == user_post_path(conn, :show, user, post)     assert Repo.get_by(Post, @valid_attrs)   end    test &quot;does not update chosen resource and renders errors when data is invalid&quot;, %{conn: conn, user: user} do     post = build_post(user)     conn = put conn, user_post_path(conn, :update, user, post), post: %{&quot;body&quot; =&gt; nil}     assert html_response(conn, 200) =~ &quot;Edit post&quot;   end    test &quot;deletes chosen resource&quot;, %{conn: conn, user: user} do     post = build_post(user)     conn = delete conn, user_post_path(conn, :delete, user, post)     assert redirected_to(conn) == user_post_path(conn, :index, user)     refute Repo.get(Post, post.id)   end <\/code><\/pre>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u0438\u0445 \u0432\u0441\u0435, \u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <b>mix test<\/b> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0435\u043b\u0451\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b!<\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u043b\u0430\u0433\u0438 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0438 \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u043e\u0432\u0430\u043b\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0438 \u043d\u0430 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438. \u041c\u044b \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u0441\u0442\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<pre><code class=\"ruby\">test &quot;redirects when the specified user does not exist&quot;, %{conn: conn} do   conn = get conn, user_post_path(conn, :index, -1)   assert get_flash(conn, :error) == &quot;Invalid user!&quot;   assert redirected_to(conn) == page_path(conn, :index)   assert conn.halted end <\/code><\/pre>\n<p>  \u041c\u044b \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u043b\u0438 <b>:user<\/b> \u0432 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 <b>setup<\/b>, \u0442. \u043a. \u0437\u0434\u0435\u0441\u044c \u0435\u0433\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435.<\/p>\n<p>  \u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043f\u043e\u0441\u0442.<\/p>\n<pre><code class=\"ruby\">test &quot;redirects when trying to edit a post for a different user&quot;, %{conn: conn, user: user} do   other_user = User.changeset(%User{}, %{email: &quot;test2@test.com&quot;, username: &quot;test2&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})   |&gt; Repo.insert!   post = build_post(user)   conn = get conn, user_post_path(conn, :edit, other_user, post)   assert get_flash(conn, :error) == &quot;You are not authorized to modify that post!&quot;   assert redirected_to(conn) == page_path(conn, :index)   assert conn.halted end <\/code><\/pre>\n<p>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0430\u0448\u0438\u043c <i>\u043f\u043b\u043e\u0445\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c<\/i>, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 <b>Repo<\/b>. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e <b>edit<\/b> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u042d\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0430 <b>authorize_user<\/b>! \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0444\u0430\u0439\u043b, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>mix test<\/code> \u0438 \u0434\u043e\u0436\u0434\u0438\u0442\u0435\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432:<\/p>\n<pre><code class=\"bash\">....................................... Finished in 0.4 seconds 39 tests, 0 failures Randomized with seed 102543 <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a-\u0442\u043e! \u041f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0435\u043c\u0430\u043b\u043e! \u0417\u0430\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 (\u0438 \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439 \u0431\u043b\u043e\u0433) \u0441 \u043f\u043e\u0441\u0442\u0430\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u043f\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u0418 \u0443 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438! \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0434\u043e\u0445\u043d\u0443\u0442\u044c. \u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u044d\u0442\u0443 \u0441\u0435\u0440\u0438\u044e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0440\u043e\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Markdown, \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u043e\u0440\u0432\u0451\u043c\u0441\u044f \u0432 \u043a\u0430\u043d\u0430\u043b\u044b \u0441 \u0436\u0438\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!<\/p>\n<h2>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430<\/h2>\n<p>  \u041c\u043d\u043e\u044e \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u0430 \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443 \u043a\u0430\u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0442\u0430\u043a \u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443 \u0432\u0441\u0435\u0439 \u0441\u0435\u0440\u0438\u0438. \u0427\u0435\u043c \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u0435\u0439\u0447\u0430\u0441. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0441\u0430\u043c\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0438\u043b\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u043d\u0438\u044f \u0432 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u042d\u043b\u0438\u043a\u0441\u0438\u0440\u0430 \u0432 \u0440\u0443\u043d\u0435\u0442\u0435, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u043b\u044e\u0441\u0430\u043c\u0438, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u0438 \u0440\u0435\u043f\u043e\u0441\u0442\u0430\u043c\u0438. \u042d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043b\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e <a href=\"http:\/\/wunsh.ru\/?utm_source=habrahabr&amp;utm_medium=content&amp;utm_campaign=blog-phoenix-2\">\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u042d\u043b\u0438\u043a\u0441\u0438\u0440\u0430<\/a> \u0432 \u0446\u0435\u043b\u043e\u043c.<\/p>\n<p>  \u041e\u0431\u043e \u0432\u0441\u0435\u0445 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044f\u0445, \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u043f\u043b\u043e\u0445\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u0438\u0448\u0438\u0442\u0435 \u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u0431\u0443\u0434\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/313482\/\"> https:\/\/habrahabr.ru\/post\/313482\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/bab\/544\/80a\/bab54480ad8d41418519f4b2d5a79a71.png\"\/><\/p>\n<p>  \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u00ab<i>Elixir \u0438 Phoenix \u2014 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0443\u0434\u0430 \u0434\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430. \u0423\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0421\u0430\u0439\u0442\u044b \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u044b\u0435 \u0438\u0433\u0440\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0442\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u043e\u0441\u043b\u0443\u0436\u0430\u0442 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0441\u043b\u0443\u0436\u0431\u0443. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0438\u0437 11 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0424\u0435\u043d\u0438\u043a\u0441 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a. \u041d\u043e \u043d\u0435 \u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u043a\u0443\u043a\u0441\u0438\u0442\u044c\u0441\u044f, \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0431\u0443\u0434\u044f\u0442 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u042d\u043b\u0438\u043a\u0441\u0438\u0440 \u043b\u0438\u0431\u043e \u0441\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u0431\u043b\u043e\u0433\u0430, \u0447\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435 \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e. \u041f\u0440\u043e\u0448\u0443 \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u0437\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0451\u0442\u043a\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043b\u0438\u0431\u043e \u0438\u0434\u0442\u0438 \u043d\u0430 \u043e\u043f\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435!<\/i>\u00bb  <\/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-280596","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280596","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=280596"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280596\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}