, , Room.find(roomId) " ". .
, .
.attributes .
, , , . user.attributes,
{ "name" => "max", "email" => "max@max.com", "id" => 5 }.
user.select { |k,v| k.in?("name", "email") }, to_json .
to_json , .attributes . , , API:
class User
def attributes
super.reject { |k,v| v.in?("password") }
end
end
, JSON:
render json: { users: @users.map(&:attributes) }.to_json, status: 200
, .
Another approach is to use jbuilderand create json views for your posts.
source
share