dimanche 6 janvier 2019

How do I render a partial within an iterator in a view? | ruby on rails

I'm trying to display a form from another controller in a view within an iterator.

Every time I try to run the code it gives me an error: 'NoMethodError at / undefined method `model_name' for nil:NilClass'

I've tried rendering the partial from another controller and I've also tried rendering a partial within the same controller but both return an error. This is might be because it's within iterator for another collection?

<% @services.each do |service| %>

  <div class='service-info'>
    <%= service.name %>
    <%= service.description %>
  </div>

  <%= simple_form_for(@visit) do |f| %>
    <%= f.error_notification %>
    <%= f.error_notification message: 
    f.object.errors[:base].to_sentence 
    if f.object.errors[:base].present? %>

    <%= f.input :service %>
    <%= f.input :visit_date %>
    <%= f.input :note %>

    <%= f.button :submit %>
  <% end %>

<% end %>

I would like the 'visit' form to appear below each 'service' in the view.

Aucun commentaire:

Enregistrer un commentaire