Property from attr_accessor does not show when I render json
问题 In Rails, I have a User model. I added attr_accessor :score to the model. If I render the JSON for one user, I do not see the "score" attribute. Why is this? user = User.find(3) user.score = 55 render json: user 回答1: render json: user, methods: [:score] attr_accessor is alternative for getter and setter method so it is a method and as I have mentioned we can call it as above 来源: https://stackoverflow.com/questions/30641623/property-from-attr-accessor-does-not-show-when-i-render-json