lazyload.jsの使い方まとめ
色んな使い方があるんですね。
参考になります。ありがとうございます。
関連記事
- 作者: 株式会社シフトブレイン
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2013/11/26
- メディア: 単行本
- この商品を含むブログ (5件) を見る
DEPRECATION WARNING cleanup! is deprecated and will be removed from Rails 5.1
Rails5でdelayed_jobを起動したら、以下のようなWARNINGが出力されました。
DEPRECATION WARNING: cleanup! is deprecated and will be removed from Rails 5.1 (use Rails.application.reloader.reload! instead of cleanup + prepare) (called from <top (required)> at bin/delayed_job:5
気持ちが悪いのGoogle大先生に聞いてみたところ下記がヒットしました。
請負になりますが、
initializers配下にdj_rails5_patches.rbを下記のように作りました。
config/initializers/dj_rails5_patches.rb
module DelayedWorkerPatches def reload! return unless self.class.reload_app? if defined?(ActiveSupport::Reloader) Rails.application.reloader.reload! else ActionDispatch::Reloader.cleanup! ActionDispatch::Reloader.prepare! end end end module Delayed class Worker prepend DelayedWorkerPatches end end
これで、ワーニングは出力されないようになりました。 ありがうございます。
関連記事
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/17
- メディア: 単行本
- この商品を含むブログを見る
autocomplete off 対策には、autocomplete new-password
クロームなんかで、パスワードフィールドに勝手に入力してくるのやめて欲しいなと思って
autocomplete='off'
を設定しても、効かないじゃん!って思ったことありませんか?
そんなときは、new-passwordです。
autocomplete='new-password'
そうすると、空で表示してくれるようです。 ただ、まだ全部のブラザには対応していないんじゃないかという噂もあるの注意して使ってください。
slimのフォームのサンプルは以下です。
.col-xs-12 .form-group = f.label :email = f.text_field :email, class: 'form-control' .col-xs-12 .form-group = f.label :password = f.password_field :password, autocomplete: 'new-password', class: 'form-control'
関連記事
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/17
- メディア: 単行本
- この商品を含むブログを見る
RailsのAction Mailerを使ってSendGridのカテゴリーを設定する
RailsのAction Mailerを使ってSendGridのカテゴリーを設定する方法です。
まずSendGridはこちら
SendGridは、主にメール配信のサービスになります。 最近使いはじめて、最高に便利なサービスです。
無料の利用枠もあるので、興味のある方は是非使ってみてください。
で、本題に入ります。
SendGridでは、メール毎にカテゴリーを設定して、配信することが出来て、 どのカテゴリーのメールが、届いたとか、開かれたとか、クリックされたとか カテゴリ毎にグルーピングしながら、解析するこができる機能があるんです。
でで、RailsのAction Mailerを使ってカテゴリーを設定するには、
以下の様に、メールのヘッダに SMTPAPIパラメータにcateoryを設定する必要があります。
def signup_mail xsmtp_api_params = { category: ['signup'] } headers['X-SMTPAPI'] = JSON.pretty_generate(xsmtp_api_params) opt = {} opt[:to] = 'aaaaaa@mail.com' opt[:subject] = '件名aaaaaa' mail(opt) end
こんな感じで、設定すると、このメールにsignupカテゴリーが設定されます。
SMTPAPIの説明についてはSendGridのブログを参考にしてください。
関連記事
- 作者: 高橋征義,諸橋恭介
- 出版社/メーカー: ソフトバンククリエイティブ
- 発売日: 2008/05/31
- メディア: 単行本
- 購入: 37人 クリック: 567回
- この商品を含むブログ (92件) を見る
参考記事
本当にありがとうございます。
(1点 header[‘X-SMTPAPI’] => headers[‘X-SMTPAPI’] が正解だと思われます。)
ActionView::MissingTemplateの対策
ActionView::MissingTemplate
そうです。 Railsでviewでテンプレートが無いときに発生します。
基本的には、テンプレートを準備しなかったミスだとは思うんですが、
動的に部分テンプレートを見つけて描画したりするときなどは、 もしテンプレートがあれば、その部分テンプレートを描画。 テンプレートがなければ、何もしないでスキップするなんて、 処理をやりたいことがあると思います。
そんな時に便利なのが、
lookup_context.exists?
です。
使い方は
- if lookup_context.exists?(@shop_code, "shop", true) = render("shop/#{@shop_code}")
仮に、下記のような、テンプレートファイルがあったときに
views/shop/_shop_123.html.slim
@shop_codeが以下のような、テンプレートファイル名と一致すれば、そのテンプレートを描画してくれます。
@shop_code = 'shop_123'
下記のようにマッチしなければ、そのままスキップ
@shop_code = 'shop_456'
関連記事
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/17
- メディア: 単行本
- この商品を含むブログを見る
Awesome Nested Setのチートシート
こちらRailsのカテゴリを階層で管理してくれるGem Awesome Nested Setです
そのチートシートです。
主に使いそうなところ
これで一気にループ回せます。
Category.each_with_level(Category.root.self_and_descendants) do |category, level| ... end
使いそうなメソッド一覧
my_cat.root root for this node my_cat.level the level of this object in the tree (e.g. root = 0) my_cat.parent the node's immediate parent my_cat.children array of immediate children (just those in the next level) my_cat.ancestors array of all parents, parents' parents, etc, excluding self my_cat.self_and_ancestors array of all parents, parents' parents, etc, including self my_cat.siblings array of brothers and sisters (all at that level), excluding self my_cat.self_and_siblings array of brothers and sisters (all at that level), including self my_cat.descendants array of all children, children's children, etc., excluding self my_cat.self_and_descendants array of all children, children's children, etc., including self my_cat.leaves array of all descendants that have no children
my_cat.root? true if this is a root node my_cat.child? true if this is a child node (i.e. it has a parent) my_cat.is_ancestor_of?(obj) true if nested by any obj my_cat.is_or_is_ancestor_of?(obj) true if nested by any obj or self is obj my_cat.is_descendant_of?(obj) true if self is nested under obj my_cat.is_or_is_descendant_of?(obj) true if self is nested under obj or self is obj my_cat.leaf? true if this is a leaf node (i.e. it has no children)
関連記事
- 作者: 掌田津耶乃
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/17
- メディア: 単行本
- この商品を含むブログを見る
GitHubでForkしたリポジトリをmargeする
下記の様に、cloneして作ったリポジトリに対して、親のmyapp.gitをmargeする方法です。
$ git clone git@bitbucket.org:xxxxxx/myapp.git
org_originという名前で、親のリポジトリを参照できるようにします。
$ git remote add org_origin git@bitbucket.org:xxxxxx/myapp.git
後は, fetchとmergeすれば完了です
$ git fetch org_origin $ git merge org_origin/master
関連記事
参考記事
ありがとうございました