Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion context/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ def create
end

def destroy

if current_user.id == params[:id].to_i

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В принципе, нам не обязательно получать идентификатор пользователя. Достаточно посмотреть в session и если там есть user_id - удалить этот ключ. Так тоже годится.

session.delete :user_id
redirect_to root_path, notice: 'Вы успешно разлогинились'
else
redirect_to root_path
flash[:error] = 'Вы кого выйти хотите?'
end
end

end
10 changes: 9 additions & 1 deletion context/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@

<body>
<header class="app">
<h1 class="app-title"><%= t('.title') %></h1>
<%= link_to root_path do %>
<h1 class="app-title"><%= t('.title') %></h1>
<% end %>
<div style="float:right">
<% if current_user %>
<%= current_user.name %>
<%= link_to 'Выйти', session_path(current_user), method: :delete %>
<% end %>
</div>
</header>

<% flash.each do |type, content| %>
Expand Down