Tableless model JSON serialization in Rails
===

I have tableless model (like it was shown in #219 railscast):
    
    class MyModel
      include ActiveModel::Conversion
      extend ActiveModel::Naming
  
      attr_accessor :attr1, :attr2, :attr3, :attr4

      private
        def initialize(attr1 = nil)
          self.attr1 = attr1
        end
    
        def persisted?
          false
        end
    end

Then I'm trying to render JSON in controller:

    @my_model = MyModel.new
    render json: @my_model.to_json(only: [:attr1, :attr2])

but it renders JSON with all the attributes of the model.

I've tried to add

    include ActiveModel::Serialization

but it didn't change rendered JSON.

How can I render JSON with only necessary attributes of my tableless model?

I'm using Rails 3.2.3