Quentin Guillaume

Learning Resources

I have try to watch as many videos as possible but lot of them where not interesting

  • December 12, 2018 at 10:13 AM
  • Last updated over 5 years ago
  • Visible to group members and anyone with the link
Drifting Ruby

Episode 50 - Rails API - Active Model Serializer

class ApplicationSerializer < ActiveModel::Serializer include Rails.application.routes.url_helpers default_url_options[:host] = 'api.demo.dev' end class UserSerializer < ApplicationSerializer attributes :id, :first_name, :last_name, :show attribute :email, if: :current_user attribute :edit_link, if: :current_user_is_owner has_many :phones def show UsersController.render(:show, assigns: { user: object}, layout: false ).squish end def edit_link edit_user_url(object) end def current_user_is_owner scope == object end end class PhoneSerializer < ApplicationSerializer attributes :name, :phone_number end