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
関連記事
参考記事
ありがとうございました
RubyでStringを配列に変換する
rubyでStringを配列に変換する方法です。
使う関数は
split(pattern)
です。
たとえば
080-1234-5678
を
tel = '080-1234-5678' tel.split('-')
すると
["080", "1234", "5678"]
という感じに配列に変換してくれます。
配列に分割出来なかったら
例えば、
“00-00"を'-‘で配列にすると
"00-00".split('-')
以下のような結果になりますが
["00", "00"]
もし、"00-00"を'=‘で分割しようとすると
"00-00".split('=')
結果は、以下のように、その文字列自体を配列に入れて返してくれます
["00-00"]
正規表現を使って分割
これまで、文字列を使って分割してきましたが、正規表現を使って分割することもできます。
’32145617741345’なんて文字列を、'1'で分割するときに
'32145617741345'.split('1')
と書いてもいいですが、
'32145617741345'.split(/1/)
としても、以下のような結果が取得できます。
["32", "456", "774", "345"]
今回の例だと単純過ぎるので、そんな使い方はあまりしないと思いますが、 もっと複雑なパターンで分割したいときなどは、正規表現も有効に使えると思います。
関連記事
恋するプログラム―Rubyでつくる人工無脳 (プレミアムブックス版)
- 作者: 秋山智俊
- 出版社/メーカー: マイナビ出版
- 発売日: 2016/11/28
- メディア: 単行本
- この商品を含むブログを見る
AWS EC2のAmazonLinuxでタイムゾーンをUTCから日本時間に変更する
作業は主に2つ
- /etc/sysconfig/clockの編集
- /etc/localtime のリンク先に東京の時間帯ファイルを設定
/etc/sysconfig/clockの編集
/etc/sysconfig/clockに設定されている タイムゾーンをUTC から Asia/Tokyo に変更します
vim /etc/sysconfig/clock
ZONE="Asia/Tokyo" UTC=true
/etc/localtime のリンク先に東京の時間帯ファイルを設定
/etc/localtime と時間帯ファイル(Asia/Tokyo)にシンボリックリンクを作成する。
sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
きっとこれでよいはず。
関連記事
Amazon Web Services パターン別構築・運用ガイド
- 作者: NRIネットコム株式会社,佐々木拓郎,林晋一郎,小西秀和,佐藤瞬
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2015/03/25
- メディア: 大型本
- この商品を含むブログ (2件) を見る