rails hide field in json

Solutions on MaxInterview for rails hide field in json by the best coders in the world

showing results for - "rails hide field in json"
Assia
07 Jul 2017
1respond_to do |format|
2  format.json { render :json => @user, :except=> [:ip] } # or without format block: @user.to_json(:except => :ip)
3end
4
Teddy
06 Apr 2020
1class User < ActiveRecord::Base
2  def to_json(options={})
3    options[:except] ||= [:ip]
4    super(options)
5  end
6end
7
Léopold
23 Apr 2019
1class User < ApplicationRecord
2  def as_json(options={})
3    options[:except] ||= [:ip]
4    super(options)
5  end
6end
7