0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

capistrano で日本語をサーバまで渡すのに、数値参照を使った

Posted at

メンテナンスモードに入る時に、理由を引数に渡すことができる gem がある
biola/turnout

rake maintenance:start reason="メンテナンスの終了は19時を予定しております"

これを capistrano 経由で実行できないかと思った。

namespace :maintenance do
  task :start, :reason do |_, args|
    reason = args[:reason]
    on release_roles :all do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, "maintenance:start reason='#{reason}'"
        end
      end
    end
  end
end

すると、下記のエラーメッセージが出た。

SSHKit::Runner::ExecuteError: Exception while executing as ****: incompatible character encodings: ASCII-8BIT and UTF-8

どうやら日本語(UTF-8)を使えないということなので、数値参照に変換して渡すことにした。
使った gem は threedaymonk/htmlentities

namespace :maintenance do
  task :start, :reason do |_, args|
    require "htmlentities"
    reason = HTMLEntities.new.encode(args[:reason], :hexadecimal) if args[:reason]
    on release_roles :all do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, "maintenance:start reason='#{reason}'"
        end
      end
    end
  end

数値参照は便利。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?