How to create ActiveRecord tableless Model in Rails 3

后端 未结 7 2240
终归单人心
终归单人心 2020-12-30 03:05

I am trying to create a Active Record tableless Model. My user.rb looks like this

class User < ActiveRecord::Base

  class_inheritable_accessor :columns

         


        
相关标签:
7条回答
  • 2020-12-30 03:59

    Just for anyone still struggling with this. For rails 2.x.x

    class TestImp < ActiveRecord::Base
    
      def self.columns
        @columns ||= []
      end
    end
    

    For rails 3.1.x you can either include ActiveModel (as explained by @ducktyped) without inheriting from ActiveRecord or If you do need to inherit from ActiveRecord::Base due to some reason then the above with one other addition:

    class TestImp < ActiveRecord::Base
    
      def attributes_from_column_definition
        []
      end
    
      def self.columns
        @columns ||= []
      end
    end
    
    0 讨论(0)
提交回复
热议问题