I have no idea what could possibly be causing this. I am making my second nested form in an app. I have a website for students to get jobs. The Job model and form refers to work done off of the site and simply lists a student's real world jobs. It is a nested form and is part of a model called Resume. I have another model, completely different, called Schedule. Schedule belongs_to a model called Project. I am trying to make a nested form so a user can create a schedule. Both forms use javascript to dynamically make new forms on the page as needed. For some reason, when I try to go to the page with the schedule form, I am told:
Missing partial schedules/job_fields, application/job_fields
This makes no sense as jobs and schedules have no relationship whatsoever. It shouldn't be looking for a jobs field partial. Here is view code for the schedule form:
<% @projects.each do |project| %>
<%= form_for project do |f| %>
<%= f.fields_for :schedules do |builder| %>
<%= render 'schedule_fields', :f => builder %>
<% end %>
<p><%= link_to_add_fields "Add Schedule", f, :schedules %>
<p><%= f.submit "Submit" %></p>
<% end %>
<% end %>
Here is the partial '_schedule_fields.html.erb'
<p class = "fieldo">
<%= f.label :title %><br />
<%= f.text_field :title %><br />
<%= f.label :task %><br />
<%= f.text_field :task %><br />
<%= f.hidden_field :_destroy %>
<%= link_to_function "remove", "remove_fields(this)" %>
</p>
And here is the jquery:
//Dynamic forms
function remove_fields(link) {
$(link).prev("input[type=hidden]").val("1");
$(link).closest(".fieldo").hide();
}
function add_fields(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + association, "g");
$(link).parent().before(content.replace(regexp, new_id));
}
Now here's something interesting. If I make a file '_job_fields.html.erb' in the views/schedules directory and copy and paste the content from '_schedule_fields.html.erb', the form works perfectly. I can't figure out why it is searching for a job_fields partial when i explicitly say in the form schedules. How do I get this working with the schedule_fields partial? Thanks!
It looks like you're not lining up arguments correctly. (If you're using anything in your application helper, you should give that too.)
Your link_to function looks like this
link_to_add_fields "Add Schedule", f, :schedules
but your javascript is calling for different parameters:
function add_fields(link, association, content)
If you match them up, you're getting f = association, which is wrong. :schedules is the association. I'd check out this railscast for more help: http://railscasts.com/episodes/403-dynamic-forms
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.