4

In my application I have a model that is below;

class Init < ActiveRecord::Base
  attr_accessor :clientAvailability
  attr_accessible :returnCode, :returnMessage, :tokenCode, :updateURL
end

In here when I've added the **attr_accessor** later on and when I try to apply **render json: init** it doesn't show the **clientAvailability** property even though I've set it as;

init=Init.new
init.clientAvailability="3"

When I debug it I can see that it is set, but doesn't simply show up when I try to render it as json. What could be the thing I'm missing?

Ali
  • 5,338
  • 12
  • 55
  • 78

1 Answers1

14

Is clientAvailability a column in the DB? If not, then I suppose it is the default way - to serialize only the DB attributes. But you can do:

render json: init, methods: [:clientAvailability]

to include clientAvailability attribute.

khustochka
  • 2,346
  • 20
  • 29