Skip to content

Commit

Permalink
Section: Allow description to be set for SEO (#2055)
Browse files Browse the repository at this point in the history
- #1155

- Meta description tags are useful for SEO; and maybe even useful for
  #1988

- I would love if we allowed `Section#title` to be set as well
  • Loading branch information
zspencer authored Dec 21, 2023
1 parent 166dafa commit 9d31b6b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Room < ApplicationRecord
has_many :gizmos, dependent: :destroy, inverse_of: :room, class_name: :Furniture
accepts_nested_attributes_for :gizmos

validates :description, length: {maximum: 300, allow_blank: true}

def full_slug
"#{space.slug}--#{slug}"
end
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<%= tag :meta, name: :turbo_visit_control, content: turbo_visit_control %>
<%- end %>

<%- if current_room&.description %>
<%= tag :meta, name: :description, content: current_room.description %>
<%- end %>


<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/rooms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<%= render "text_field", attribute: :name, form: room_form %>
<%= render "text_field", attribute: :slug, form: room_form %>

<%= render "text_area", attribute: :description, form: room_form %>

<h3>Privacy and Security</h3>

<%= render "radio_group", attribute: :access_level, options: Room::access_levels.values, form: room_form %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231221025246_add_section_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSectionDescription < ActiveRecord::Migration[7.1]
def change
add_column :rooms, :description, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2023_12_13_043812) do
ActiveRecord::Schema[7.1].define(version: 2023_12_21_025246) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -259,6 +259,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "space_id"
t.string "description"
t.index ["slug", "space_id"], name: "index_rooms_on_slug_and_space_id", unique: true
t.index ["space_id"], name: "index_rooms_on_space_id"
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/room_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
it { is_expected.to have_many(:gizmos).inverse_of(:room).dependent(:destroy) }
it { is_expected.to belong_to(:space).inverse_of(:rooms) }

describe "#description" do
it { is_expected.to validate_length_of(:description).is_at_most(300).allow_blank }
end

describe ".slug" do
it "creates unique slugs by space scope" do
space_1 = Space.create(name: "space1")
Expand Down

0 comments on commit 9d31b6b

Please sign in to comment.