Home > front end >  Rails5: partial render is looking for file in wrong location
Rails5: partial render is looking for file in wrong location

Time:10-25

I have a method that makes a bunch of variables and ends with a call to render a partial...

  def add_shift 
...
    render :partial => 'assignments/edit'
  end

But when this page tries to render it gives me this gnarly error...

Missing partial volunteer_events/_editform_perfect, application/_editform_perfect with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
  * "/home/fonso/back-expirement/app/views"

this is the code for the breaking view...

<div class="modal fade" id="edit_event">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <div class="col-sm-8 left border-right">
          <h4 class="modal-title">Edit Assignment</h4>
        </div>
        <div class="col-sm-4 right d-flex flex-row">
          <h4 class="modal-title">Who's Working</h4>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        </div>
      </div>       
        <%= render 'editform_perfect', assignment: @assignment %>
    </div>
  </div>
</div>

The partial is located assignments/_edit.html and assignments/_editform_perfect

So why am I getting this interesting error and how can I fix it so I see the partials?

CodePudding user response:

From the error message, it appears you're rendering the view from a controller volunteer_events_controller. So when you attempt to render the partial editform_perfect it will by default look in views/volunteer_events/ directory.

You'll need to provide the path to the partial in the view.

<%= render partial: 'assignments/editform_perfect'.... %>

  • Related