From d72b065bccbd00c02c74913178c8cfe23d7e78e8 Mon Sep 17 00:00:00 2001 From: webmstk Date: Wed, 10 Aug 2016 14:09:53 +0300 Subject: [PATCH] lesson 14 --- context/app/controllers/sessions_controller.rb | 8 +++++++- context/app/views/layouts/application.html.erb | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/context/app/controllers/sessions_controller.rb b/context/app/controllers/sessions_controller.rb index 4bf8d25..1d6bfa3 100644 --- a/context/app/controllers/sessions_controller.rb +++ b/context/app/controllers/sessions_controller.rb @@ -19,7 +19,13 @@ def create end def destroy - + if current_user.id == params[:id].to_i + session.delete :user_id + redirect_to root_path, notice: 'Вы успешно разлогинились' + else + redirect_to root_path + flash[:error] = 'Вы кого выйти хотите?' + end end end diff --git a/context/app/views/layouts/application.html.erb b/context/app/views/layouts/application.html.erb index f54b749..b3bebe6 100644 --- a/context/app/views/layouts/application.html.erb +++ b/context/app/views/layouts/application.html.erb @@ -10,7 +10,15 @@
-

<%= t('.title') %>

+ <%= link_to root_path do %> +

<%= t('.title') %>

+ <% end %> +
+ <% if current_user %> + <%= current_user.name %> + <%= link_to 'Выйти', session_path(current_user), method: :delete %> + <% end %> +
<% flash.each do |type, content| %>