ノンカフェインであなたにやさしい

Ruby,Rails,HTML,CSS,Reactなど

Messenger Ninja 名前,写真を変更できるようアップデート

半月前にリリースしたMessengerで相手の名前と写真を隠すChrome拡張を、名前と写真を自由に変更できるようアップデートしました。

chrome.google.com

設定方法

アイコンを右クリックしてメニューから オプション を選択

f:id:kuronekopunk:20180917104015p:plain

設定したい名前とURLを入れて保存してください🙌

f:id:kuronekopunk:20180917103949p:plain

FBメッセの相手のアイコンと名前を隠すChrome拡張をリリース🎉

カフェとかでメッセンジャーのやり取りをしていると相手の名前やアイコンがモロに出ていて気になったので
アイコンと名前をダミーにするChrome拡張「Messenger Ninja」を作りました🎉🎉🎉

chrome.google.com

突貫で作ったのでダミーアイコンや名前が雑ですが、今後ユーザーが設定できるようにしたいなと思ってます。

Rspecでテストをスキップさせる

(あまり良くないんだけど)ちょっとスキップしたい場面に出くわしたのでメモ

ブロックを skip とするか

RSpec.describe "an example" do
  skip "is skipped" do
  end
end

頭に x をつければいいだけらしい🙄

RSpec.describe "an example" do
  xit "is skipped using xit" do
  end

  xspecify "is skipped using xspecify" do
  end

  xexample "is skipped using xexample" do
  end
end

※参考 relishapp.com

RailsでCloudinaryを使う

CarrierWave、Cloudinaryを使った画像アップロードの方法です。

cloudinary.com

今回のバージョン

ruby: 2.5.0
rails: 5.1.6

Cloudinaryに登録

Cloudinaryに登録して使える状態にしておきます。
登録後サイト内で cloudinary.yml がダウンロードできるはずなのでしておきましょう。

Gem追加

Gemfileに下記を追加

gem 'carrierwave'
gem 'cloudinary'
bundle install

Uploader作成

rails g uploader Image

Cloudinaryを使うよう修正

storage :file

を以下に変更

  if Rails.env.production?
    include Cloudinary::CarrierWave
  else
    # 本番以外ではローカルに保存する
    storage :file
  end

ファイルアップロードしたいモデルにマウント

例Userモデル

class User < ApplicationRecord
  mount_uploader :image, ImageUploader
end

cloudinary.yml追加

最初にダウンロードしたcloudinary.ymlを config/cloudinary.yml に配置

フォーム修正

fileのinputとサムネイルを表示 _form.html.erb

<%= image_tag(@user.image_url(:thumbnail), :width => 80, :height => 80) %>
<%= f.file_field :image %>

webpackerでA JSON text must at least contain two octets! (JSON::ParserError)と怒られた話

エラー内容

rails crails s をすると以下のエラーが
webpack系のjsonのパースが上手くいっていないよっていうエラーっぽい

Exiting
Traceback (most recent call last):
    51: from bin/rails:4:in `<main>'
  50: from bin/rails:4:in `require'
   49: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands.rb:18:in `<top (required)>'
  48: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/command.rb:46:in `invoke'
    47: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/command/base.rb:65:in `perform'
  46: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
   45: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
  44: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    43: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:142:in `perform'
  42: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:142:in `tap'
   41: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:147:in `block in perform'
  40: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:51:in `start'
    39: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:89:in `log_to_stdout'
  38: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/server.rb:354:in `wrapped_app'
   37: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/commands/server/server_command.rb:27:in `app'
  36: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/server.rb:219:in `app'
    35: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/server.rb:319:in `build_app_and_options_from_config'
  34: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/builder.rb:40:in `parse_file'
   33: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `new_from_string'
  32: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `eval'
    31: from config.ru:in `<main>'
  30: from config.ru:in `new'
   29: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `initialize'
  28: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `instance_eval'
    27: from config.ru:1:in `block in <main>'
  26: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
   25: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
  24: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    23: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
  22: from /share/config/environment.rb:5:in `<top (required)>'
   21: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
  20: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    19: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
  18: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
   17: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
  16: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `call'
    15: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `each'
  14: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
   13: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
  12: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    11: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
  10: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    9: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
   8: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
     7: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webpacker-3.5.3/lib/webpacker/railtie.rb:79:in `block in <class:Engine>'
   6: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webpacker-3.5.3/lib/webpacker.rb:26:in `bootstrap'
    5: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webpacker-3.5.3/lib/webpacker/commands.rb:15:in `bootstrap'
   4: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webpacker-3.5.3/lib/webpacker/manifest.rb:18:in `refresh'
     3: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/webpacker-3.5.3/lib/webpacker/manifest.rb:70:in `load'
   2: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/bundler/gems/json-7f4cfd853f2c/lib/json/common.rb:155:in `parse'
    1: from /home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/bundler/gems/json-7f4cfd853f2c/lib/json/common.rb:155:in `new'
/home/vagrant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/bundler/gems/json-7f4cfd853f2c/lib/json/common.rb:155:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)

対応

public/packs/manifest.json が完全な空ファイルになっていたので空のjsonを入れてあげる

{}

このファイル何も編集していないはずなのになぜ急に…