Compare commits

..

No commits in common. "6f32112b2afb942b6e4b06e94e45e17407daad0f" and "b75f9277ccc443e0a28bfa369d844cf310064ec9" have entirely different histories.

23 changed files with 14 additions and 166 deletions

View File

@ -12,4 +12,3 @@
# KAMAL_RUNTIME # KAMAL_RUNTIME
echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds" echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds"
kamal app exec --reuse "bin/rails db:migrate"

View File

@ -15,7 +15,6 @@ gem "bcrypt", "~> 3.1.7"
gem "bootsnap", require: false gem "bootsnap", require: false
gem "kaminari" # Pagination gem "kaminari" # Pagination
gem "solid_cache"
group :development, :test do group :development, :test do
gem "debug", platforms: %i[ mri mingw x64_mingw ] gem "debug", platforms: %i[ mri mingw x64_mingw ]

View File

@ -229,8 +229,6 @@ GEM
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0) websocket (~> 1.0)
solid_cache (0.1.0)
rails (>= 7)
sprockets (4.2.1) sprockets (4.2.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4) rack (>= 2.2.4, < 4)
@ -283,7 +281,6 @@ DEPENDENCIES
puma puma
rails (~> 7.1) rails (~> 7.1)
selenium-webdriver selenium-webdriver
solid_cache
sprockets-rails sprockets-rails
stimulus-rails stimulus-rails
turbo-rails turbo-rails

View File

@ -1,11 +1,11 @@
:root { :root {
--border-color: #282828; --border-color: gray;
--highlight-color: #d65d0e; --highlight-color: #D36200;
--background-color: #928374; --background-color: #CCC;
--dark-background-color: #1d2021; --dark-background-color: #333;
--inset-background-color: #fbf1c7; --inset-background-color: #FFFFFF;
--alert-border-color: #98971a; --alert-border-color: #800000;
--form-error-color: #cc241d; --form-error-color: #FF0000;
} }
* { * {

View File

@ -23,10 +23,6 @@ form#micropost_form {
} }
} }
ul#microposts {
list-style-type: none;
}
.micropost { .micropost {
margin: 1em auto; margin: 1em auto;
padding: .5em; padding: .5em;
@ -37,16 +33,4 @@ ul#microposts {
text-align: right; text-align: right;
font-size: .8em; font-size: .8em;
} }
h5 {
display: inline;
}
ul.micropost-tags {
list-style-type: none;
display: inline;
li {
display: inline;
}
}
} }

View File

@ -17,7 +17,6 @@ class MicropostsController < ApplicationController
def create def create
micropost = Micropost.new(micropost_params) micropost = Micropost.new(micropost_params)
micropost.user = helpers.current_user micropost.user = helpers.current_user
micropost.set_tags(*parse_tags(params[:tags])) if params[:tags]
if micropost.save if micropost.save
redirect_to micropost, notice: t(".created") redirect_to micropost, notice: t(".created")
else else
@ -30,7 +29,6 @@ class MicropostsController < ApplicationController
def edit; end def edit; end
def update def update
@micropost.set_tags(*parse_tags(params[:tags])) if params[:tags]
if @micropost.update(micropost_params) if @micropost.update(micropost_params)
redirect_to @micropost, notice: t(".updated") redirect_to @micropost, notice: t(".updated")
else else
@ -48,10 +46,6 @@ class MicropostsController < ApplicationController
private private
def parse_tags(tags)
tags.split
end
def micropost_params def micropost_params
params.require(:micropost).permit( params.require(:micropost).permit(
:content, :content,

View File

@ -9,8 +9,7 @@ class SessionsController < ApplicationController
def new; end def new; end
def create def create
@user = User.authenticate_by(username: params[:username], password: params[:password]) if @user.present? && @user.authenticate(params[:password])
if @user
session[:user_id] = @user.id session[:user_id] = @user.id
redirect_to root_path, notice: t(".logged_in") redirect_to root_path, notice: t(".logged_in")
else else

View File

@ -1,19 +0,0 @@
# frozen_string_literal: true
class TagsController < ApplicationController
skip_before_action :require_login, only: [:index, :show]
before_action :set_tag, only: [:show]
def index
@tags = Tag.all
.page(params[:page])
end
def show; end
private
def set_tag
@tag = Tag.find_by(name: params[:id])
end
end

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
module MicropostsHelper
def tag_string(micropost)
micropost.tags.map(&:name).join(" ")
end
end

View File

@ -10,11 +10,4 @@ class Micropost < ApplicationRecord
has_many :microposts_tags has_many :microposts_tags
has_many :tags, through: :microposts_tags has_many :tags, through: :microposts_tags
def set_tags(*tag_names)
tag_names.each do |tag_name|
tag = Tag.find_or_create_by(name: tag_name)
tags << tag unless tags.include?(tag)
end
end
end end

View File

@ -4,8 +4,4 @@ class Tag < ApplicationRecord
validates :name, presence: true validates :name, presence: true
has_many :microposts_tags has_many :microposts_tags
has_many :microposts, through: :microposts_tags has_many :microposts, through: :microposts_tags
def to_param
name
end
end end

View File

@ -3,7 +3,5 @@
<%= f.rich_text_area :content %> <%= f.rich_text_area :content %>
<%= text_field_tag :tags, tag_string(@micropost) %>
<%= f.submit button_text %> <%= f.submit button_text %>
<% end %> <% end %>

View File

@ -1,13 +1,5 @@
<div class="micropost"> <div class="micropost">
<%= micropost.content %> <%= micropost.content %>
<% unless micropost.tags.empty? %>
<h5>Tags:</h5>
<ul id="micropost-<%= micropost.id %>-tags" class="micropost-tags">
<% micropost.tags.each do |tag| %>
<li><%= link_to tag.name, tag %></li>
<% end %>
</ul>
<% end %>
<div class="created_at"> <div class="created_at">
<%= link_to "Edit", edit_micropost_path(micropost) if micropost.user == current_user %> <%= link_to "Edit", edit_micropost_path(micropost) if micropost.user == current_user %>
<%= link_to micropost.created_at.strftime("%Y-%m-%d %H:%M"), micropost %> <%= link_to micropost.created_at.strftime("%Y-%m-%d %H:%M"), micropost %>

View File

@ -1,12 +0,0 @@
<h2><%= t(".tags") %></h2>
<% if @tags.empty? %>
<p><%= t(".empty") %></p>
<% else %>
<ul id="tags">
<% @tags.each do |tag| %>
<li><%= link_to tag.name, tag %></li>
<% end %>
</ul>
<%= paginate @tags %>
<% end %>

View File

@ -1,3 +0,0 @@
<h2><%= @tag.name %></h2>
<%= render @tag.microposts %>

View File

@ -52,3 +52,7 @@ builder:
remote: remote:
arch: arm64 arch: arm64
host: ssh://kamal@tsvallender.co.uk host: ssh://kamal@tsvallender.co.uk
healthcheck:
path: /sessions/new
port: 3000

View File

@ -56,7 +56,7 @@ Rails.application.configure do
config.log_tags = [ :request_id ] config.log_tags = [ :request_id ]
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :solid_cache_store # config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment). # Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque

View File

@ -1,6 +0,0 @@
en:
tags:
index:
tags: Tags
empty: You dont have any tags yet

View File

@ -14,7 +14,4 @@ Rails.application.routes.draw do
resources :blog_posts resources :blog_posts
resources :microposts resources :microposts
resources :tags, only: [:index, :show]
get "up" => "rails/health#show", as: :rails_health_check
end end

View File

@ -1,12 +0,0 @@
# This migration comes from solid_cache (originally 20230724121448)
class CreateSolidCacheEntries < ActiveRecord::Migration[7.0]
def change
create_table :solid_cache_entries do |t|
t.binary :key, null: false, limit: 1024
t.binary :value, null: false, limit: 512.megabytes
t.datetime :created_at, null: false
t.index :key, unique: true
end
end
end

9
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_10_19_192600) do ActiveRecord::Schema[7.1].define(version: 2023_10_19_172703) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -77,13 +77,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_19_192600) do
t.index ["tag_id", "micropost_id"], name: "index_microposts_tags_on_tag_id_and_micropost_id" t.index ["tag_id", "micropost_id"], name: "index_microposts_tags_on_tag_id_and_micropost_id"
end end
create_table "solid_cache_entries", force: :cascade do |t|
t.binary "key", null: false
t.binary "value", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true
end
create_table "tags", force: :cascade do |t| create_table "tags", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false

View File

@ -1,21 +0,0 @@
require "test_helper"
class TagMicropostsTest < ActionDispatch::IntegrationTest
test "tags can be added to microposts" do
@user = users(:trevor)
sign_in(@user)
get new_micropost_path
assert_response :success
post microposts_path, params: {
micropost: {
content: "An interesting post",
},
tags: "foo bar baz",
}
assert_response :redirect
follow_redirect!
assert_includes response.body, "foo"
assert_includes response.body, "bar"
assert_includes response.body, "baz"
end
end

View File

@ -17,21 +17,4 @@ class MicropostTest < ActiveSupport::TestCase
@micropost.content = nil @micropost.content = nil
assert_not @micropost.valid? assert_not @micropost.valid?
end end
test "can add tags" do
assert_empty @micropost.tags
assert_difference "@micropost.tags.count", +3 do
@micropost.set_tags("foo", "bar", "baz")
end
end
test "duplicate tags are not added" do
assert_empty @micropost.tags
assert_difference "@micropost.tags.count", +3 do
@micropost.set_tags("foo", "bar", "baz")
end
assert_no_difference "@micropost.tags.count" do
@micropost.set_tags("bar", "baz")
end
end
end end