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| %>