2019-01-01から1年間の記事一覧
何故かCRAで作ったデフォルトの/public/robots.txtが以下のようになっているのでCard Validatorで何回試してもTwitterCardが表示されない。 # https://www.robotstxt.org/robotstxt.html User-agent: * 以下のように変更したら直った。 # https://www.robots…
display: flex; justify-content: center; を外側の要素に指定するとずれるので display: flex; justify-content: flex-start; にする。 See the Pen RwNZBeZ by to_m0ya (@gazimum) on CodePen.
前提 UserはVideoとCommentを持っている。 それらに付いたLikeをwhere('created_at > ?', Time.now - 1.days)とかで一定期間に制限してカウントして足し合わせて、その合計が多い順にUserを並べたい。 PostgreSQL 以下、例示のために必要な部分だけ抜き出し…
A. renderで渡す @res = Hoge.where(name: hoge) @items = ActiveModel::Serializer::CollectionSerializer.new( @res, serializer: HogeSerializer, some_values: user_signed_in? && current_user.some_values ) render json: { items: @items.page(@page)…
何が起こった? YouTube埋め込みプレーヤーを使っているページで同一のURLがhistoryにpushされていた。つまりページAからYouTube埋め込みプレーヤーのあるページBに遷移し動画の読み込みが完了した後に「前のページに戻る」操作をしてもそこは同じページBで…
やりたいこと # Item has_many :item_tag_relations, dependent: :destroy has_many :tags, through: :item_tag_relations, dependent: :destroy # ItemTagRelation belongs_to :item belongs_to :tag Tag name: string という状況で「"red"と"blue"と"yello…
なぜ? WEBページのPVやAUはGoogle Analyticsを見ればわかるが、ページによってはタブの遷移などでURLが割り振られていない動作があり、それはAPIコールの回数を解析することでしか知ることができない。そして解析はSQLを使っていい感じにやりたい。 やりか…
使い方例 準備 Gemfile gem 'google-api-client', '~> 0.30.6' /config/initializers/youtube.rb require 'google/apis/youtube_v3' module YouTube class Client Service = Google::Apis::YoutubeV3::YouTubeService.new Service.key = ENV.fetch('DEVELOPE…
詰まった点 Serializer側で、「ユーザはログインしているか」と「ユーザは過去にLikeしたか」を判断して値を返さなければいけないがActiveModel::Serializer::CollectionSerializerを使ってどうやってやる? 解決策 ActiveModel::Serializer::CollectionSeri…
作り終わってから思い出して書き始めたので抜けがあるかもしれない バックエンド(Rails API) APIモードでRailsアプリを作ってCORSの設定とかをいい感じにする aws-sdk-s3とactive_model_serializersをGemfileに追加してbundle install S3にバケットを作っ…
class User < ActiveRecord::Base # いろんな処理 def token_validation_response UserSerializer.new(self, root: false).as_json end end github.com
See the Pen bGGpEqr by to_m0ya (@gazimum) on CodePen.
やりたいこと Redisを使って「急上昇」を実装したい やってみたやりかた ソート済みセット型のインスタンスとして 以下を使う スコアの最新の増減を記録する用:score_diff 過去のスコアを記録する用:score 手順 アイテムのスコアを変動させる diffは変動量…
やりたいこと Redisのソート済みセット型を簡単にコピー やりかた zunionstore dst 1 src 参考 redis.shibu.jp
withHoge()でWrapする処理をrenderの中で毎回行ってしまっていてinputのonChangeでrenderが呼ばれるたびにフォーカスが外れてしまっていた。 See the Pen HOC000 by to_m0ya (@gazimum) on CodePen.