From 1f88e343334a9f92e94a775f1483163e41386c65 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Mon, 3 Jul 2023 12:05:17 +0200 Subject: [PATCH] Routes avec la date --- app/controllers/extranet/posts/posts_controller.rb | 1 + app/views/admin/communication/extranets/posts/show.html.erb | 2 +- app/views/extranet/posts/posts/_list.html.erb | 4 +++- config/routes/extranet.rb | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/extranet/posts/posts_controller.rb b/app/controllers/extranet/posts/posts_controller.rb index 3705bd3fb..fd434c990 100644 --- a/app/controllers/extranet/posts/posts_controller.rb +++ b/app/controllers/extranet/posts/posts_controller.rb @@ -9,6 +9,7 @@ class Extranet::Posts::PostsController < Extranet::Posts::ApplicationController end def show + # TODO utiliser la date pour permettre des slugs identiques à dates différentes @post = current_extranet.posts.find_by! slug: params[:slug] breadcrumb end diff --git a/app/views/admin/communication/extranets/posts/show.html.erb b/app/views/admin/communication/extranets/posts/show.html.erb index d0c64ed9e..8515a14c5 100644 --- a/app/views/admin/communication/extranets/posts/show.html.erb +++ b/app/views/admin/communication/extranets/posts/show.html.erb @@ -31,7 +31,7 @@ <% content_for :action_bar_right do %> <%= link_to t('open'), - posts_post_url(@post.slug, host: @post.extranet.url, extranet_id: nil), + posts_post_url(date: @post.published_at.strftime('%Y-%m-%d'), slug: @post.slug, host: @post.extranet.url, extranet_id: nil), target: :_blank, class: 'btn btn-light btn-xs' if @post.published %> <%= preview_link %> diff --git a/app/views/extranet/posts/posts/_list.html.erb b/app/views/extranet/posts/posts/_list.html.erb index 6d0ba3ad4..616e507b6 100644 --- a/app/views/extranet/posts/posts/_list.html.erb +++ b/app/views/extranet/posts/posts/_list.html.erb @@ -9,7 +9,9 @@ <b><%= post %></b><br> <span class="text-muted"><%= l post.published_at.to_date %><span> </p> - <%= link_to t('extranet.posts.read_post'), posts_post_path(post.slug), class: ' btn btn-outline-primary stretched-link' %> + <%= link_to t('extranet.posts.read_post'), + posts_post_path(date: post.published_at.strftime('%Y-%m-%d'), slug: post.slug), + class: ' btn btn-outline-primary stretched-link' %> </div> </article> <% end %> diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb index f62c4b0e9..70d9300e1 100644 --- a/config/routes/extranet.rb +++ b/config/routes/extranet.rb @@ -27,7 +27,7 @@ namespace :posts do get 'categories' => 'categories#index', as: :categories get 'categories/:slug' => 'categories#show', as: :category # Categories before slug ! - get ':slug' => 'posts#show', as: :post + get ':date/:slug' => 'posts#show', as: :post root to: 'posts#index' end namespace :library do -- GitLab