Note system [params]

2

I'm creating a note system with clients, projects, activities, professional and pointing, all parts pass and save correctly, less the part of note posting.

Follows the error image while trying to point it out.

Followthenew.html.erbcode

<%= 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 kind of lost. PS²: I'm using enumerize to set the options in status.

    
asked by anonymous 30.10.2017 / 04:41

1 answer

0

The error occurs because the model is expecting to receive a Professional object for its .professional attribute, but is receiving a String , which I believe is the id of that collection_select , try changing it in your form to that the value is entered in professional_id . Try this:

<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: This :user_id field is id of Professional , I do not know how your business model is, but usually the id field is used.

    
31.10.2017 / 12:40