Searchkickを使ってidでorderするときの罠

Searchkickでidでorderしようとしたのに全然動かなかったのでその対応方です。

github.com

通常の使い方

Product.search(order: { id: :desc })

これだとなぜかidでソートされない

idでソートする方法

orderの中身を配列で囲む

Product.search(order: [{ id: :desc }])

マジすか…

github.com

基本的な使い方はこちら

qiita.com

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 %>