0

I am newbie ruby programmer and I´m suffering this error

This is part of my "new" form to create new "Subasta" objects

<%= form_for @subasta, url: {action: "crear"} do |s| %>
<%= s.label :precioinicial, 'Precio inicial' %>
<%= s.number_field :precioinicial,  class: "form-control", in: 1...10000 %>
<%= render :partial => "puja_minima", :locals=>{:s=>s} %>

This "new" form has a partial with another Subasta´s field

<%= s.label :puja_minima, 'La puja empezará por' %>
<%= s.number_field :puja_minima,  class: "form-control", in: 0...10000, disabled: true %>

The problem is the field 'puja_minima' doesn`t reachs the controller and it´s necessary:

validates :puja_minima, presence: true

The error is:

The form contains 2 errors. * Puja minima La puja mínima no debe estar vacía

Marino
  • 106
  • 9

2 Answers2

3

You have disabled :true on your puja_minima field,make it as false.

<%= s.number_field :puja_minima,  class: "form-control", in: 0...10000, disabled: false %>

OR

Even just like this

<%= s.number_field :puja_minima,  class: "form-control", in: 0...10000 %>

Update

As you want it to be non-editable,use :readonly => true.

<%= s.number_field :puja_minima,  class: "form-control", in: 0...10000, :readonly => true %>
Pavan
  • 33,316
  • 7
  • 50
  • 76
  • Don´t wanna that field to be editable. It´s a calculated field – Marino Jun 08 '14 at 15:47
  • Thanks Pavan, works for me! But I don´t include "disabled: false". For what it´s useful? <%= s.number_field : puja_minima, class: "form-control", in: 0...10000, :readonly => true %> – Marino Jun 08 '14 at 15:57
  • @Marino You can neglect the `disabled : false`. I will update my answer. – Pavan Jun 08 '14 at 16:00
0

There's nothing wrong with the partial - the input is disabled.

Disabled inputs aren't submitted to the controller.

Shaun
  • 549
  • 3
  • 10
  • How do you avoid editing a input field and submits to the controller? Do you have any example? – Marino Jun 08 '14 at 15:40
  • If it's not editable, why rely on the form? You could set it in the controller. Alternatively, also submit a hidden field containing the value. – Shaun Jun 08 '14 at 15:43