mardi 5 mai 2015

Display money-rails value in nested form

I have a nested form where a user can add multiple instances of a class. This nested form is part of a larger wizard (multi-step form) where the user can go forwards and backwards through the process.

In my rails application I'm using the money rails gem. When a user goes backwards in the wizard, I'd like to populate the fields so they can see what they've previously entered. Up until now, I've had no issue doing this with other nested objects. However, displaying a money field is stumping me.

# the field
<%= f.text_field :guarantor_net_worth, :value => ( f.object.guarantor_net_worth_cents.nil? ? nil : f.object.guarantor_net_worth_cents ) %>

# In console when I see if there is a value assigned to an object that I'm testing
guarantor_net_worth_cents: 4564600, guarantor_net_worth_currency: "CAD"

The thing I can't seem to figure out is when I set :value => f.object.guarantor_net_worth_currency, the field displays CAD, but won't seem to display the cents. To debug futher, I used puts to see the ID's of the objects I was creating and searching them in console and they are being created properly with the values being passed through params as they should.

Aucun commentaire:

Enregistrer un commentaire