mobyletteをやめる
https://github.com/tscolari/mobylette
いま関わっているrailsプロジェクトにmobyletteっていうgemが入っているのだけど、メンテナンスされていないのでやめたかった。
最近になってようやくをこれをやめることができそうなのでメモがてらに書いておく。  
mobyletteは、モバイル端末からアクセスがあったらmobileというformatのテンプレートを返すっていう振る舞いをする。
rails4以降には本体にvariantっていうmobylette相当の機能が入っていて、これを使えばmobyletteを捨てることができる。   
mobyletteはmobile用のテンプレートを format として扱うが、railsのvariantは、formatとは別概念なので修正が全体に及んでしまってめんどくさかった。
mobyletteをやめるためにやることは、
- mobileをformatとして扱う実装をやめる
- index.mobile,erbという名前を `- index.html+mobile,erbにリネームする
- mobyletteの振る舞いを維持するために以下controllerのbefore_actionとして定義しておく
- mobyletteは、html formatがなかったらmobile formatへのfallbackするようになっていたので、これを維持した
 
  def use_variant_mobile_if_miss_default_template
    if is_mobile_request?
      request.variant = :mobile
    else
      # default templateがなかったら && variant mobileがあればvariant mobileにする
      if !template_exists?(action_name.to_s, _prefixes, variants: request.variant)
        if template_exists?(action_name.to_s, _prefixes, variants: [:mobile])
          request.variant = :mobile
        end
      end
    end
  end
以上。
- 
      category:
      
- rails