How can I extend ActiveRecord::Associations to a frozen_record in rails -


i'm using frozen record gem in rails upload yaml file containing fixed questions app. once they're uploaded want use salequalifier model grab each question, associate answer, , use state machine move through question tree.

i've got frozen record gem working , yaml file uploads fine. when tried associating model new model (salequalifier) got 'method_missing': undefined method 'belongs_to' question:class (nomethoderror)

as result added include activerecord::associations components in order let me associate new record salequalifier question belongs_to :sale_qualifier- throws:

'method_missing': undefined method 'dangerous_attribute_method?' question:class (nomethoderror)

according search, error thrown when i've declared method beforehand. don't know defined, frozen_record gem files can see set frozenrecord following:

module frozenrecord  class base   extend activemodel::naming   include activemodel::conversion   include activemodel::attributemethods   include activemodel::serializers::json   include activemodel::serializers::xml  end end 

i'm starting think using gem might overkill, , perhaps should load questions normal activerecord::base model, frozenrecord idea, that's i'm trying achieve.

my code:

class question < frozenrecord::base  include activemodel::validations  include activerecord::associations  validates :next_question_id_yes, :question_text, :answer_type, presence: true  belongs_to :sale_qualifier  self.base_path = 'config/initializers/' end 

salequalifier:

class salequalifier < activerecord::base  has_many :questions end 

can me unpick mess seem have dug myself into? maybe ought dig out yaml upload functions frozenrecord , dump them question model without using gem.

so in end, frozen_record wasn't adding app seems. given files loaded yaml , there's no controller, presume there's no way question records updated, unless has compromised db , inserted own questions.yml file.

as such changed question model follows load yaml , insert database new question records:

class question < activerecord::base  validates :next_question_id_yes, :question_text, :answer_type, presence: true  belongs_to :sale_qualifier   file.open("#{rails.root}/config/initializers/questions.yml", 'r') |file|    yaml::load(file).each |record|       question.create(record)    end  end end 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -