Skip to content

Commit

Permalink
Личный кабинет. Часть 1
Browse files Browse the repository at this point in the history
  • Loading branch information
maclen2007 committed Jan 5, 2024
1 parent d95eeec commit 805f411
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -17,3 +17,8 @@
.alert:empty {
display: none;
}

.logout {
margin-top: 20px;
text-align: center;
}
16 changes: 16 additions & 0 deletions app/controllers/profiles_controller.rb
@@ -0,0 +1,16 @@
class ProfilesController < ApplicationController

before_action :authenticate_user!, only: [:index]

def index
@user = User.find(current_user.id)
@posts = @user.post
end

def show
@user = User.find(params[:id])
@posts = @user.post
render :index
end

end
2 changes: 2 additions & 0 deletions app/helpers/profiles_helper.rb
@@ -0,0 +1,2 @@
module ProfilesHelper
end
2 changes: 1 addition & 1 deletion app/views/posts/_post.html.erb
Expand Up @@ -8,7 +8,7 @@
</h3>
</a>
<p class="post-meta">Posted by
<a href="#"><%= post.user.email %></a>
<a href="<%= url_for(profile_path(id: post.user.id)) %>"><%= post.user.email %></a>
on <%= post.created_at.strftime('%d-%m-%Y %H:%M') %>
</p>
</div>
Expand Down
46 changes: 46 additions & 0 deletions app/views/profiles/index.html.erb
@@ -0,0 +1,46 @@
<% content_for :title do %>
Записи пользователя <%= @user.email %>
<% end %>

<main role="main" class="container">
<div class="row">
<% if params[:action] == 'index' %>
<div class="col-md-3 mb-3 mt-1">
<div class="card">
<div class="card-body">
<div class="h2">
<!-- Email автора -->
<%= @user.email %>
</div>
</div>

<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="<%= url_for(new_post_path) %>" style="text-decoration:underline">Создать пост</a>
</li>
<li class="list-group-item">
<a href="<%= url_for(edit_user_registration_path) %>" style="text-decoration:underline">Смена пароля</a><br />
</li>
<li class="list-group-item">
<div class="h6 text-muted">
<!-- Количество записей -->
Записей: <%= @posts.count %>
</div>
</li>
</ul>
</div>
<div class="logout">
<%= button_to "logout", destroy_user_session_path, { method: :delete, class: 'btn btn-danger' } %>
</div>
</div>
<% end %>
<div class="col-md-9">
<!-- Начало блока с отдельным постом -->
<% @posts.each do |post| %>
<%= render 'posts/post', post: post %>
<% end %>
<!-- Остальные посты -->
<!-- Здесь будет постраничная навигация паджинатора -->
</div>
</div>
</main>
3 changes: 3 additions & 0 deletions config/routes.rb
Expand Up @@ -9,4 +9,7 @@
get 'about', to: 'pages#about', as: 'about'
resources :posts

get 'profiles/index', to: 'profiles#index', as: 'cabinet'
get 'profiles/show/:id', to: 'profiles#show', as: 'profile'

end
7 changes: 7 additions & 0 deletions test/controllers/profiles_controller_test.rb
@@ -0,0 +1,7 @@
require "test_helper"

class ProfilesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit 805f411

Please sign in to comment.