System of notes [params]

Asked

Viewed 23 times

2

I am creating a system of appointments with clients, projects, activities, professionals and appointments, all parts pass and save correctly, except the part of the launch of the notes.

Follow the error image when trying to make the note.

Erro apontamento

Follow the code of the new.html.erb

<%= form_for (@timesheet), html:{ class: "form-horizontal" } do |f| %>

<!-- Alert Error -->
<%= error_messages_for @timesheet %>
<!-- Title -->
<div class="form-group">
  <%= f.label :activity_id, "Atividade:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= collection_select(:timesheet, :activity_id, Activity.all, :object_id, :name) %>
  </div>
</div>

<div class="form-group">
  <%= f.label :professional, "Profissional:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= collection_select(:timesheet, :professional, Professional.all, :user_id, :name) %>
  </div>
</div>

<div class="form-group">
  <%= f.label :day, "Dia:", class: "control-label col-sm-2" %>
  <div class="col-md-2 col-sm-9">
    <%= f.text_field :initial_hour, :class => 'form-control date', placeholder: 'DD/MM/AAAA' %>
  </div>
</div>

<div class="form-group">
  <%= f.label :initial_hour, "Data/Hora Inicial:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.time_select :initial_hour, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="form-group">
  <%= f.label :final_hour, "Data/Hora Final:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.time_select :final_hour, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="form-group">
  <%= f.label :quantity_hours, "Quantidade de horas:", class: "control-label col-sm-2" %>
  <div class="col-md-2 col-sm-9">
    <%= f.text_field :quantity_hours, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="form-group">
  <%= f.label :situation, "Situação:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.select :status, Timesheet.status.options %>
  </div>
</div>

<div class="form-group">
  <%= f.label :remunerated, "Remunerado:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.check_box :remunerated, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="form-group">
  <%= f.label :billed, "Faturado:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.check_box :billed, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="form-group">
  <%= f.label :displacement, "Deslocamento:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= f.check_box :displacement, :class => 'form-control', :required => true %>
  </div>
</div>

<div class="hr-line-dashed"></div>

<!-- Buttons -->
<div class="form-group">
  <div class="col-sm-4 col-sm-offset-2">
    <%= link_to "Cancelar", timesheets_path, :class => 'btn btn-white' %>
    <%= f.submit "Salvar", :class => 'btn btn-primary' %>
  </div>
</div>

<% end %>

PS: I’m new to Rails and I’m a little lost. PS²: I am using enumerize to set the options in the status.

1 answer

0

The error occurs because the model is waiting to receive an object Professional for your attribute .professional, but is receiving a String, which I believe to be the id that collection_select, try changing in your form so that the value is inserted in professional_id. Try this way:

<div class="form-group">
  <%= f.label :professional_id, "Profissional:", class: "control-label col-sm-2" %>
  <div class="col-md-6 col-sm-9">
    <%= collection_select(:timesheet, :professional_id, Professional.all, :user_id, :name) %>
  </div>
</div>

Doubt: that field :user_id is the id of Professional, I don’t know what your business model looks like, but you usually use the field id even.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.