quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

RailsCasts #409 Active Model Serializers

#409 Active Model Serializers - RailsCasts

  • as_json in model
  • rails g serializer article
    • app/serializers
  • render json: @article, root: false
    • default_serializer_options (private method)
  • def url ; article_url(object) ; end
  • has_many :comments
    • embed :ids, include: true
  • def attributes ; data = super ; data[:edit_url] = ... ;
  • scope.admin? in serializer : current_user private -> protected
    • serialization_scope :view_context
    • delegate :current_user, to: :scope
  • data-attribute in index.html

json, api系も選択肢ありすぎ問題ある気がする