money-rails icon indicating copy to clipboard operation
money-rails copied to clipboard

How to insert the value from a form field into the model?

Open bvirlet opened this issue 4 months ago • 1 comments

Hi folks,

Thanks for this great library.

I'm currently running in an error. When using the following form:

  <div class="field form-group">
    <%= form.label :amount, 'Amount %>
    <%= form.number_field :amount, step: :any, class: 'form-control' %>
  </div>

Controller:

  def create
    @convertible_note = @company.convertible_notes.build(convertible_note_params)
    if @convertible_note.save
      redirect_to portfolio_company_path(@portfolio, @company), notice: 'Convertible Note was successfully created.'
    else
      render :new, status: :unprocessable_entity
    end
  end

…

  def convertible_note_params
    params.require(:convertible_note).permit(:amount, :amount_cents)
  end

Model:

  monetize :amount_cents, with_model_currency: :currency

I'm getting the following error on creation: Amount cents is not a number

Am I doing something wrong? What pattern do you recommend to properly fix this?

Thanks!

bvirlet avatar Oct 17 '24 15:10 bvirlet