mozyのかきおき

mozyの読書感想文や思考置き場

js.erb とは何者か

経緯

RailsAjaxなどを使ってよしなに動作を作りたいときに js.erbファイルを使って$('#id-hogera').append("<%= j(render 'form', ....) %>"); みたいなことをしたりするけど、この文法って結局なんやねんって思ったのでメモ

つまりは

.js.erbファイルは、コントローラのアクションで、アクションが完了したときにJavaScriptを実行したいときなどにつかう。
たとえば、ajaxでフォームを送信して、全部完了したときにアラート出したい時とかに使える。
んで、そのブラウザに返されるJavaScriptは、erbによってレンダリングされ流ので、いわゆる普通のerbの場合と同じように、カスタム文字列/変数などを入れることができる。

参考

超詳しく書いている。ナイス stackoverflow.com

GitHub にバグを見つけて報告したら速攻で修正してくれた話

f:id:mozy_ok:20190114125918p:plain

経緯

普段通りGitHubを使って業務をしていたところ、ちょっとした表示のバグを見つけて、それを報告したら、速攻で直してくれたという貴重な体験をしたので日記として書いておく。
誰かのバグ報告のメールを書くときの参考になれば幸いです。

動作

こんな感じにちょっとした表示の不具合を見つけた。


github bug

送ったメール

こんな感じに動画を添付して、サポート(support あっと github.com)に連絡をしてみた。
再現手順を書くのがコツかもしれない。

Hi, GitHub Dev team

I found a minor display bug in the [Your repositories] page.
( ex, https://github.com/MozyOk?tab=repositories )

Steps to reproduce
1. Enter characters on the search form. 
2. Delete all entered characters.
3. Two buttons at the bottom of the page are displayed.

Please check the attached video for more details. 

Thanks.

---
Mozy Okubo.
My GitHub account is https://github.com/MozyOk/.

結果

Hi Mozy,

Sorry you have experienced this problem.

I’ve escalated your report to our engineering team for further investigation.

While we don’t yet have a specific ETA, we’ll be sure to update you as soon as there’s any news to share.

てな感じに、再現したよーって言われて、エンジニアが直すので少し待っててねと言われました。

そして数日後、

Hi Mozy,

I just wanted to let you know that our engineers have recently deployed a fix for this issue, so it should now be resolved.

Thanks for your patience, and for taking the time to report the trouble! Let us know if there's anything else we can do.

という訳で速攻修正されていました!

コツ

外資系の企業にいる方や、国外とのやりとりがある方には当たり前かもしれないですが、時差を考えてメールを飛ばすのが早く連絡が返ってくるコツだったりします。
例えば、
米国西海岸に連絡をする場合は、日本時間でいう8~10時くらいの朝一に連絡をすると、現地が15~17時なので反応が返って来やすいです。
ヨーロッパ側に連絡をするときは、日本時間でいう18~20時くらいの終業時に連絡をすると、現地が10~12時くらいなので反応が返って来やすいです。
基本的には現地に比べて時差がプラスならば夜に、マイナスならば朝に、連絡をするってのがコツかもしれませんね。

まとめ

GitHubのサポート速攻返ってくるし、修正も早いしで素晴らしい!

Rails で foundation を install しようとしたらエラー

経緯

こんな感じに foundation:install をしたらエラーが出た。

$ rails g foundation:install
Traceback (most recent call last):
    41: from bin/rails:4:in `<main>'
    40: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    39: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    38: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    37: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    36: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    35: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    34: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    33: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    32: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
    31: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke'
    30: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform'
    29: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
    28: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    27: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    26: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/generate/generate_command.rb:21:in `perform'
    25: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command/actions.rb:17:in `require_application_and_environment!'
    24: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    23: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    22: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    21: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    20: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    19: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    18: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    17: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    16: from /Users/mozy/GitHub/rails-react/config/application.rb:7:in `<main>'
    15: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler.rb:114:in `require'
    14: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `require'
    13: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `each'
    12: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `block in require'
    11: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `each'
    10: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
     9: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
     8: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
     7: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
     6: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
     5: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
     4: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/foundation-rails-6.5.1.0/lib/foundation-rails.rb:2:in `<main>'
     3: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
     2: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
     1: from /Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/Users/mozy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': cannot load such file -- sprockets/es6 (LoadError)

試行錯誤

require': cannot load such file -- sprockets/es6 とあったのでとりあえず、
bundle update sprockets-rails したが解決せず

結論

以下のリンクにあったように foundation-rails のバージョンを下げて対応したら動作するようになった。

This appears to be an issue with the newly released 6.4.1 version. Try reverting back to Foundation 6.3.1, if you're not already using it.

gem 'foundation-rails', '~> 6.3.1''

That did the trick for me when I was having the same issue this evening. Didn't have time to look into the asset pipeline to figure out exactly where the problem originated from.

github.com

バージョンを下げた時のGemの変更部分

sass のGemバージョンも下がってるな

Fetching sass 3.4.25 (was 3.7.3)
Installing sass 3.4.25 (was 3.7.3)
Using sprockets 3.7.2
Fetching sprockets-es6 0.9.2
Installing sprockets-es6 0.9.2
Fetching foundation-rails 6.3.1.0 (was 6.5.1.0)
Installing foundation-rails 6.3.1.0 (was 6.5.1.0)

プログラミング学習はスクリーンキャスト教材を選ぶ時代

経緯

いろんな新しい技術を身につけようと思った時に、最近はYoutubeで検索すると大抵の技術は、チュートリアルが見つかったりすることに気がついて、こちらで学ぶようにしている。
最近、こんな感じのを学んだ。


Haskell Tutorial


Ansible - A Beginner's Tutorial, Part 1

関連して

Rails

Railsを学ぶ時には、RailsCast という超有名なサイトがあったのだけれども、最近は更新がされていないので、こちら、GO RAILS が最強。
かなりの量のコンテンツがあって、基本的にRailsでやりたいことはこのサイトの動画にあると思って大丈夫なレベルで便利なサイトです。
僕も事あるごとに見返したりしています。

gorails.com

Laravel

これは、Laravel版のスクリーンキャストサイトで、こちらもかなりの量のコンテンツがあって、参考にできる動画がたくさんあります。

laracasts.com

C#

これはYoutubeにあるし結構わかりやすい

C# Screencasts - YouTube

Go

実はGo言語のGitHub Wikiにスクリーンキャストのリンクがあるの知ってましたか?
これはPacktの書籍などのリンクとなっているので有料だったりするんですが、先日紹介した Safaribooks Onlineなどを契約していると、動画が観れたりします。

Screencasts · golang/go Wiki · GitHub

(Safaribooks Online はこちら)
https://safaribooksonline.com
過去記事はこちら
mozy-ok.hatenablog.com

結論

まずは、公式ドキュメントをみながら、Youtubeやサイトでスクリーンキャストやライブコーディングを眺めると、その技術特有の使い方や癖などの感覚がわかるので、かなりオススメ。
書籍やウェブサイトで学習するのに比べて、いわゆる行間を読む部分が少ないので速攻で最低限の知識を得ることができると感じている。

サイトの死活監視には updown.io が最強&最高な件

まずはこのサイトをみて欲しい
Google のモニタリング状況のページです

updown.io

f:id:mozy_ok:20190110181350p:plain
Google のモニタリング

公式サイト

updown.io

SIMPLE & INEXPENSIVE WEBSITE MONITORING の名の通りシンプルでわかりやすく、かなり直感的なモニタリングサービスとなっています。
多言語対応もできています。

金額

ズバリ、5サイト を1分ごとに監視で 月2.93€ (370円程度)
安すぎる!!

使い勝手

サインインは、GitHub or Google でも可能です。 便利!!

f:id:mozy_ok:20190110181134p:plain
設定画面はこんな感じで直感的

まとめ

安くて、使い勝手が良くって即導入できる。
三拍子揃った死活監視サービス updown.io を使ってみるのいかがでしょうか!

Railsのテストを CIでかけた時に Capybara のエラーがでる原因

経緯

RailsのテストをCIでかけた時に以下のようなエラーが発生した

error:
UserRegistrationsTest#test_hogehoge:
Capybara::ElementNotFound: Unable to find option "piyo"

原因

システムテストはアプリのユーザー操作のテストに使えます。テストは、実際のブラウザまたはヘッドレスブラウザに対して実行されます。システムテストではそのために背後でCapybaraを使います。

Rails テスティングガイド | Rails ガイド

とな

関連する部分をGistにまとめた

https://railsguides.jp/testing.html#rails%E3%82%92%E5%8D%B3%E5%BA%A7%E3%81%AB%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E3%81%AB%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B · GitHub

npm run watch と npm run watch-poll の違い

違い

npm run watch と npm run watch-poll の違いは、watchは ファイルの変更をみている。 (特定のシステムの場合はうまくいかない)
watch-poll は 変更を 1秒単位などで 定期的に確認をする。

watch will listen for file changes, however, on certain systems this won't always work.

watch-poll periodically checks (polls) for changes e.g. every 1000ms it will manually check to see if any files have changed.

参考

https://stackoverflow.com/questions/44127688/difference-between-npm-run-watch-and-npm-run-watch-poll