From 44f57de50e9d646125ff6a1b8232a7291309dec0 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 29 Jun 2020 11:34:40 +0200 Subject: [PATCH] suite url --- app/controllers/public/circuits_controller.rb | 10 ++++++++- .../public/menu_items_controller.rb | 10 ++++----- .../public/organisateurs_controller.rb | 9 +++++++- app/models/circuit.rb | 4 ++++ app/models/organisateur.rb | 4 ++++ app/views/admin/circuits/_form.html.haml | 1 + app/views/admin/organisateurs/_form.html.haml | 1 + app/views/public/circuits/_circuit.html.haml | 2 +- .../organisateurs/_organisateur.html.haml | 2 +- config/routes.rb | 21 +++++++++++++++++-- .../20200629091426_add_slug_to_circuits.rb | 9 ++++++++ ...0200629091433_add_slug_to_organisateurs.rb | 9 ++++++++ db/schema.rb | 6 ++++-- 13 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20200629091426_add_slug_to_circuits.rb create mode 100644 db/migrate/20200629091433_add_slug_to_organisateurs.rb diff --git a/app/controllers/public/circuits_controller.rb b/app/controllers/public/circuits_controller.rb index 6509d2e..946adbc 100644 --- a/app/controllers/public/circuits_controller.rb +++ b/app/controllers/public/circuits_controller.rb @@ -30,8 +30,16 @@ class Public::CircuitsController < ApplicationController def show - @circuit = Circuit.find(params[:id]) @circuits_active = true + + + if @circuit = Circuit.where(:id => params[:id]).first + + elsif @circuit = Circuit.where(:slug => params[:id]).first + + else + redirect_to public_circuits_path + end end diff --git a/app/controllers/public/menu_items_controller.rb b/app/controllers/public/menu_items_controller.rb index 807a6e4..0a6d918 100644 --- a/app/controllers/public/menu_items_controller.rb +++ b/app/controllers/public/menu_items_controller.rb @@ -72,14 +72,14 @@ class Public::MenuItemsController < ApplicationController menu_id = 1 @menu_item_lang = @lang.menu_item_langs.joins(:menu_item).where(:menu_items => {:menu_id => menu_id}).find_by_permalink("index") - @menu_item = @menu_item_lang.menu_item - if cookies.permanent[:visites_enquete] - cookies.permanent[:visites_enquete] =cookies.permanent[:visites_enquete].to_i + 1 + if @menu_item_lang + @menu_item = @menu_item_lang.menu_item else - cookies.permanent[:visites_enquete] = 1 + redirect_to "/" end - + + end if @menu_item and @menu_item.menu_content and @menu_item.menu_content.class.to_s == "Page" diff --git a/app/controllers/public/organisateurs_controller.rb b/app/controllers/public/organisateurs_controller.rb index 17160ed..22ca8f4 100644 --- a/app/controllers/public/organisateurs_controller.rb +++ b/app/controllers/public/organisateurs_controller.rb @@ -33,8 +33,15 @@ class Public::OrganisateursController < ApplicationController def show - @organisateur = Organisateur.find(params[:id]) @organisateurs_active = true + + if @organisateur = Organisateur.where(:id => params[:id]).first + + elsif @organisateur = Organisateur.where(:slug => params[:id]).first + + else + redirect_to public_organisateurs_path + end end diff --git a/app/models/circuit.rb b/app/models/circuit.rb index 0cdb3bb..678f276 100644 --- a/app/models/circuit.rb +++ b/app/models/circuit.rb @@ -57,5 +57,9 @@ class Circuit < ApplicationRecord #end + + before_save do + self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug + end end diff --git a/app/models/organisateur.rb b/app/models/organisateur.rb index 06cd34f..dbbdee4 100644 --- a/app/models/organisateur.rb +++ b/app/models/organisateur.rb @@ -41,5 +41,9 @@ class Organisateur < ApplicationRecord def member_label "#{self.name}" end + + before_save do + self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug + end end diff --git a/app/views/admin/circuits/_form.html.haml b/app/views/admin/circuits/_form.html.haml index 6e237f9..325bd67 100644 --- a/app/views/admin/circuits/_form.html.haml +++ b/app/views/admin/circuits/_form.html.haml @@ -9,6 +9,7 @@ = f.input :circuit_region, :label => "Région :" = f.input :name, :label => "Nom :" + = f.input :slug, :label => "Lien permanent :" = f.input :website, :label => "Site web :" = f.input :description, :label => "Description :" = f.input :person_civilite, :label => "Civilité :" diff --git a/app/views/admin/organisateurs/_form.html.haml b/app/views/admin/organisateurs/_form.html.haml index 7db720f..57a7fa5 100644 --- a/app/views/admin/organisateurs/_form.html.haml +++ b/app/views/admin/organisateurs/_form.html.haml @@ -10,6 +10,7 @@ = f.input :name, :label => "Nom :" + = f.input :slug, :label => "Lien permanent :" = f.input :website, :label => "Site web :" = f.input :description, :label => "Description :" = f.input :person_civilite, :label => "Civilité :" diff --git a/app/views/public/circuits/_circuit.html.haml b/app/views/public/circuits/_circuit.html.haml index 68f00fd..c26d979 100644 --- a/app/views/public/circuits/_circuit.html.haml +++ b/app/views/public/circuits/_circuit.html.haml @@ -3,7 +3,7 @@ =# %h3=circuit.name -=link_to [:public, circuit], :class => "circuit" do +=link_to public_circuit_path(:id => circuit.slug), :class => "circuit" do -img = "" -img = circuit.logo.file.large.medium.url if circuit.logo -img = circuit.image_file.file.large.medium.url if circuit.image_file diff --git a/app/views/public/organisateurs/_organisateur.html.haml b/app/views/public/organisateurs/_organisateur.html.haml index 26f9764..7d61b9d 100644 --- a/app/views/public/organisateurs/_organisateur.html.haml +++ b/app/views/public/organisateurs/_organisateur.html.haml @@ -1,5 +1,5 @@ -=link_to [:public, organisateur], :class => "organisateur" do +=link_to public_organisateur_path(:id => organisateur.slug), :class => "organisateur" do -img = "" -img = organisateur.logo.file.large.medium.url if organisateur.logo .img{:style => ("background-image:url('#{img}');" if img)} diff --git a/config/routes.rb b/config/routes.rb index ac21140..c9d5235 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,22 @@ Rails.application.routes.draw do + get "/USER_CREATION/1/104--36-mon-compte.html" => redirect("/fr/mon-compte.html") + get "/:lang/mon-compte.html" => "public/my_account#index", :as => :public_my_account + + get "/:lang/se-connecter.html" => "public/p_customer_auths#new", :as => :new_public_p_customer_auth + get "/:lang/creer-mon-compte.html" => "public/p_customers#new", :as => :new_public_p_customer + post "/:lang/creer-mon-compte.html" => "public/p_customers#create", :as => :public_p_customers + get "/:lang/circuits/:id.html" => "public/circuits#show", :as => :public_circuit + get "/:lang/circuits.html" => "public/circuits#index", :as => :public_circuits + + + get "/:lang/organisateurs/:id.html" => "public/organisateurs#show", :as => :public_organisateur + get "/:lang/organisateurs.html" => "public/organisateurs#index", :as => :public_organisateurs + + get "/:lang/journees-de-roulage.html" => "public/m_events#index", :as => :public_m_events + + + namespace :admin do resources :departement_frances do member do @@ -623,7 +640,7 @@ Rails.application.routes.draw do namespace :public do - get "my_account" => "my_account#index", :as => :my_account + get "my_account" => "my_account#index" resources :particulars @@ -1035,7 +1052,7 @@ Rails.application.routes.draw do - get ':slug.html', to: 'public/m_odrs#show', :as => :public_m_odr + get ':slug.html', to: 'public/menu_items#show', :as => :public_m_odr root "public/menu_items#index" diff --git a/db/migrate/20200629091426_add_slug_to_circuits.rb b/db/migrate/20200629091426_add_slug_to_circuits.rb new file mode 100644 index 0000000..fd505e9 --- /dev/null +++ b/db/migrate/20200629091426_add_slug_to_circuits.rb @@ -0,0 +1,9 @@ +class AddSlugToCircuits < ActiveRecord::Migration[6.0] + def change + add_column :circuits, :slug, :string + + Circuit.all.each do |circuit| + circuit.save + end + end +end diff --git a/db/migrate/20200629091433_add_slug_to_organisateurs.rb b/db/migrate/20200629091433_add_slug_to_organisateurs.rb new file mode 100644 index 0000000..cfab43a --- /dev/null +++ b/db/migrate/20200629091433_add_slug_to_organisateurs.rb @@ -0,0 +1,9 @@ +class AddSlugToOrganisateurs < ActiveRecord::Migration[6.0] + def change + add_column :organisateurs, :slug, :string + + Organisateur.all.each do |organisateur| + organisateur.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c38fb8..01b06ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_06_25_135439) do +ActiveRecord::Schema.define(version: 2020_06_29_091433) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -230,6 +230,7 @@ ActiveRecord::Schema.define(version: 2020_06_25_135439) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.integer "circuit_region_id" + t.string "slug" t.index ["admin_id"], name: "index_circuits_on_admin_id" end @@ -319,7 +320,7 @@ ActiveRecord::Schema.define(version: 2020_06_25_135439) do t.index ["square_image_file_id"], name: "index_data_files_on_square_image_file_id" end - create_table "departement_frances", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + create_table "departement_frances", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t| t.string "num_dep" t.string "dep_name" t.string "region_name" @@ -1381,6 +1382,7 @@ ActiveRecord::Schema.define(version: 2020_06_25_135439) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.integer "circuit_region_id" + t.string "slug" t.index ["admin_id"], name: "index_organisateurs_on_admin_id" end