virtus

Use Storext (or just Virtus) with nested array or hash objects

流过昼夜 提交于 2021-02-19 05:32:18
问题 I have a postgres DB backing my Rails app with a class with a jsonb column class Product < AR::B include Storext.model(data: {}) store_attributes :data do thing_one String thing_two Boolean # Not actually showing up in the `data` hash foos FooCollection[Foo] end end class FooCollection < Array def <<(obj) if Hash super(Coupon.new(obj) else # Other coersions end end end class Foo include Storext.model attribute :id, Integer attribute :price, Float attribute :regular_price, Float end But Foo in

Rails Form Object with Virtus: has_many association

筅森魡賤 提交于 2019-11-29 05:11:48
I am having a tough time figuring out how to make a form_object that creates multiple associated objects for a has_many association with the virtus gem . Below is a contrived example where a form object might be overkill, but it does show the issue I am having: Lets say there is a user_form object that creates a user record, and then a couple associated user_email records. Here are the models: # models/user.rb class User < ApplicationRecord has_many :user_emails end # models/user_email.rb class UserEmail < ApplicationRecord belongs_to :user end I proceed to create a a form object to represent

Rails Form Object with Virtus: has_many association

大城市里の小女人 提交于 2019-11-27 19:01:31
问题 I am having a tough time figuring out how to make a form_object that creates multiple associated objects for a has_many association with the virtus gem. Below is a contrived example where a form object might be overkill, but it does show the issue I am having: Lets say there is a user_form object that creates a user record, and then a couple associated user_email records. Here are the models: # models/user.rb class User < ApplicationRecord has_many :user_emails end # models/user_email.rb