constantizeした時にactive_support/inflector/methods.rb:268:in `const_get': uninitialized constant Hoge (NameError)と怒られる問題[Rails]

h = 'Hoge'.constantize
h.create(fuga: 'fuga')

した時に

active_support/inflector/methods.rb:268:in `const_get': uninitialized constant Hoge (NameError)

Hogeという定数、クラスがなかったため怒られてしまった。

safe_constantizeで回避

safe_constantizeを使うと存在しなかった場合 nil が返されます nilチェックしてから実行して回避

h = 'Hoge'.safe_constantize
h.create(fuga: 'fuga') unless h.nil?

rake taskの中断はreturnではなくnextだった[Rails]

task :test do
  puts 'hoge'
  return
  puts 'moge'
end

実行する

rake aborted!
LocalJumpError: unexpected return

怒られた…

rake taskの中断はreturnじゃなくてnextとのこと

task :test do
  puts 'hoge'
  next
  puts 'moge'
end

以下の場合はreturnとのこと

task :foo do
  do_something
end

def do_something
  puts "startd"
  return
  puts "end"
end

http://stackoverflow.com/questions/2316475/how-do-i-return-early-from-a-rake-task

brew updateしたら/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directoryと怒られる問題

brew update

brew update したら

$  brew update                       
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  http://docs.brew.sh/Analytics.html

Error: update-report should not be called directly!

めっちゃ怒られた

対応

他の方のブログでは brew prune で解消らしいが…

3回目の brew update で普通にupdateされました

なんだったのだろう…

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

GoogleMapAPIを使って現在地情報を取得しようとしたところ Chrome

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

Safari

[blocked] Access to geolocation was blocked over insecure connection to http://xxx.com.

とのエラーが…

GoogleMapAPIからの返り値を見ると下記のエラー文

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

原因としては、 セキュリティの関係上SSLになっているか、ドメインlocalhostなど限られた条件でないと現在地情報を使えないようになっているようです。
ローカル環境で開発しているならドメインlocalhostに設定してデバッグすれば動作します。
もしくはFirefoxならドメイン関係なく現在地情報を使えるため問題なくデバッグできました。

All in One SEO Packでアーカイブページなどの個別ページにもtitle,descriptionを設定する

All in One SEO Packがアーカイブページにディスクリプションやらのメタタグを出力してくれないなと思ったらどうやらそういう仕様らしい

以下のサイトを参考にさせていただきました。 blog.maromaro.co.jp

追加で設定するためにfunction.php以下を書き足してフィルターを噛ませます。

<?php
function aioseop_title_extention($title){
  if(is_archive()){
    $title = 'タイトル'
  }
  return $title;
}
add_filter('aioseop_title', 'aioseop_title_extention');
?>

特定のカスタム投稿タイプのアーカイブページでのみ適用

自分の場合カスタム投稿のアーカイブページで書き換えたかったので以下のように変更

<?php
function aioseop_title_extention($title){
  if(is_post_type_archive('custom_post')){
    $title = 'タイトル';
  }
  return $title;
}
add_filter('aioseop_title', 'aioseop_title_extention');
?>

管理画面からメタタグを編集できるように拡張

タイトルを管理画面から編集できるようにしたかったので
カスタム投稿タイプと同じslug名の固定ページを作って
そこのAIOSEOの情報を引っ張ってくるように書き換えました。

<?php
function aioseop_title_extention($title){
  if(is_post_type_archive('custom_post')){
    $title = get_post_meta(get_page_by_path('custom_post')->ID, _aioseop_title, true);
  }
  return $title;
}
add_filter('aioseop_title', 'aioseop_title_extention');
?>