I’m working on a projects where hunts a list of tasks associated with them. I’ve got a hunts model that accepts nested attributes for the tasks model. But I can’t my views to work right. Here’s what my views/hunts.html.erb looks like:
<h1>New Hunt</h1>
<%= form_for(@hunt) do |f| %>
<%= render 'fields', :f => f %>
<%= f.fields_for :tasks do |builder| %>
<%= render "task_fields", :f => builder %>
<% end %>
<div class="actions">
<%= f.submit "Add hunt" %>
</div>
<% end %>
Unfortunately, that doesn’t work. Rails thinks that tasks_fields is located in the hunts views. This is the error message I receive.
ActionView::MissingTemplate in Hunts#new
Showing /****/app/views/hunts/new.html.erb where line #9 raised:
Missing partial hunts/task_fields, application/task_fields with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
*****/app/views"
How do I tell rails to look in views/tasks instead of views/hunts?
Just use the name of the other folder, e.g.
will render tasks/_task_fields.html.erb