Writebook - Once

Looks like writebook is free, so I “purchased” a copy. At the bottom of the email I received it said I could download a zip, which I did.

Unpacking that zip into an empty directory, I found a Rails application that won’t work with Rails 8, or any Ruby version released on or after February 14th. So I brute forced it.

I first removed the Dockerfile and Gemfile.lock. I updated .ruby_version to 3.4.2. I commented out the following line in config/environments/production.rb:

   # SQLite is good, actually
-  config.active_record.sqlite3_production_warning = false
+  # config.active_record.sqlite3_production_warning = false

I ran the following commands:

bundle add dockerfile-rails --optimistic --group development
bin/rails generate dockerfile

I modified bin/dockerfile-entrypoint so that the line immediately above the db:prepare line reads:

if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then

I ran fly launch and accepted the defaults. It warned about configuration being used during build. I ignored that warning and proceeded with fly deploy.

Launch was successful and I get the following:

I don’t know anything about writebook, so I don’t know what more is needed to get a fully functioning system, but hopefully this helps.

3 Likes

Done!
Please read Writebook - Once - #27 by rubys then Writebook - Once - #29 by Recall45 to set up the REDIS_URL variable, this comment

Important Notes:

  • After you set up your username and password the app will redirect you to a screen that will show an error. Just refresh the page and access with the credentials you just set up
  • If you been following the tutorial from rubys, the mod that very kindly help me solve this thread, you will get to a point where he mentions something about db:prepare. This line isnt originally on the application, it only appears after successfully ran bin/rails generate dockerfile
  • The mod put two commands together 1) bundle add dockerfile-rails --optimistic --group development (you may have to run this line with the sudo prefix) 2) bin/rails generate dockerfile
  • The zip where rubys and me got the code from comes from the you received after purchase the free license. Its on the very last line P.P.S. Eager to see how we built Writebook? You can also download a zipfile with the complete source code.

First time with ruby?

If is your first time with rails, it was for me - installing rails is not easy, its a pain. Seriously you will get SO MANY times an error because of some file is ‘unauthorized’ - you installed ruby improperly.
I suggest watch a tutorial just to install the thing beforehand and dont neglect rbenv.
Here is the gemfile that worked for me. Hope it eases the process:

source "https://rubygems.org"

ruby file: ".ruby-version"

gem "rails", git: "https://github.com/rails/rails.git", branch: "main"

# Drivers
gem "sqlite3", "~> 2.2"
gem "redis", ">= 4.0.1"

# Deployment
gem "puma", ">= 5.0"

# Jobs
gem "resque", "~> 2.6.0"
gem "resque-pool", "~> 0.7.1"

# Front-end
gem "propshaft"
gem "importmap-rails"
gem "turbo-rails"
gem "stimulus-rails"

# Other
gem "jbuilder"
gem "redcarpet", "~> 3.6"
gem "rouge", "~> 4.5"
gem "bcrypt", "~> 3.1.7"
gem "image_processing", "~> 1.13"
gem "rqrcode"
gem "thruster"
gem "useragent", git: "https://github.com/basecamp/useragent.git", branch: "master"
gem "front_matter_parser"

group :development, :test do
  gem "debug"
  gem "faker", require: false
  gem "brakeman", require: false
  gem "rubocop-rails-omakase", require: false
end

group :development do
  gem "web-console"
end

group :test do
  gem "capybara"
  gem "selenium-webdriver"
end

gem "dockerfile-rails", ">= 1.7", :group => :development

gem "litestream", "~> 0.12.0"

gem "aws-sdk-s3", "~> 1.182", :require => false

Bug - Book content doesnt update

Seems like the no content can be stored. Past the front page the app cant store text, images, or sections.
Went through the docs and the logs of the application.
Apparently there was this problem every time a user tried any type of text:

2025-03-14T17:30:19Z app[d8d9263b0d9458] qro [info]E, [2025-03-14T17:30:19.932188 #664] ERROR -- : [e67336a0-d267-45d1-83ad-c1ed63b19c29] [ActiveJob] Failed enqueuing Turbo::Streams::BroadcastJob to Resque(default): Redis::CannotConnectError (Connection refused - connect(2) for 127.0.0.1:6379 (redis://localhost:6379))
2025-03-14T17:30:19Z app[d8d9263b0d9458] qro [info]I, [2025-03-14T17:30:19.933385 #664]  INFO -- : [e67336a0-d267-45d1-83ad-c1ed63b19c29] Completed 500 Internal Server Error in 46ms (ActiveRecord: 1.0ms (6 queries, 0 cached) | GC: 0.0ms)
2025-03-14T17:30:19Z app[d8d9263b0d9458] qro [info]E, [2025-03-14T17:30:19.936366 #664] ERROR -- : [e67336a0-d267-45d1-83ad-c1ed63b19c29]

Trying to resolve this issue, I set up a new redis instance in fly (dashboard > upstash redis > new, then you click on the application and read the upstash dashboard to find the redis url) with the connection string redis://default:9XXXX@fly-writebook-test3-redis.upstash.io:6379. Then I looked at any mention of redis (like redis config) and went through the files of the application.

Added Redis Intializer

Added the following file into config > initializers > redis.rb

# config/initializers/redis.rb
require "redis"

redis_url = ENV.fetch("REDIS_URL") { "redis://localhost:6379" }
REDIS = Redis.new(url: redis_url)

# Configure Resque to use this Redis connection
Resque.redis = REDIS if defined?(Resque)

Changed the cable.yml file

# config/cable.yml
development:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") %>

test:
  adapter: test

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") %>
  channel_prefix: writebook_production

Then re-deployed with env variable REDIS_URL

  1. fly deploy
  2. fly secrets set REDIS_URL=redis://default:9XXXX@fly-writebook-test3-redis.upstash.io:6379
  3. fly launch

That solved the error.

If the error persist or you cant deploy try to edit the docker file

... other content
# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development:test" \
    RAILS_ENV="production" \
    PORT="8080" \
    REDIS_URL="redis://default:9XXXX@fly-writebook-test3-redis.upstash.io:6379"

...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.