I have the following models in rails
payment_supplier.rb
class PaymentSupplier < ActiveRecord::Base
has_many :folio_has_payment_suppliers
has_many :folios, through: :folio_has_payment_suppliers, dependent: :destroy
end
folio_has_payment_supplier.rb
class FolioHasPaymentSupplier < ActiveRecord::Base
belongs_to :folio
belongs_to :payment_supplier
end
folio.rb
class Folio < ActiveRecord::Base
has_many :folio_has_payment_suppliers
has_many :payment_suppliers, through: :folio_has_payment_suppliers, dependent: :destroy
end
If I test from the console, the information is stored correctly
rails c --sandbox
ps = PaymentSupplier.new
ps.folio_ids
=> []
ps.folio_ids = [1, 4]
=> [1, 4]
ps.hotel_id = 87
ps.cantidad = 2500
ps.save
ps.folios (Me muestra los 2 folios almacenados, es decir me hace la union bien)
My problem is when I pass this to my partial payment_supplier # _form.html.erb, I save the data and save only the first value of the input, if I put ex. 1,4,7,10 only stores the 1, I infer that because for the input the values are read as a string, and in the console I pass the values to it as an array [1, 4], so I make a slight change to my model
class PaymentSupplier < ActiveRecord::Base
has_many :folio_has_payment_suppliers
has_many :folios, through: :folio_has_payment_suppliers, dependent: :destroy
serialize :folio_ids, Array
def folio_ids=(ids)
self.folio_ids = ids.split(',')
end
end
According to what I have read, what I am looking for is folio_ids to separate it by commas and store it, but when I add this last modification to my model, and I do the submit in the project the application hangs, checking in the console I get this
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/models/payment_supplier.rb:11:in 'folio_ids='
app/controllers/egr/payment_suppliers_controller.rb:16:in 'create'