Skip to content

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

Open
@bvirlet

Description

@bvirlet

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions