Question

I have two models: newsavedmap and waypoints.

My newsavedmap:

    class Newsavedmap < ActiveRecord::Base
        has_many :waypoints, :dependent => :destroy
        accepts_nested_attributes_for :waypoints
    end

The form, which lives on maptry.html.erb

    <% form_for @newsavedmap, :html=>{:id=>'createaMap'} do |f| %>
<%= f.error_messages %>
<%= f.text_field :name, {:id=>"savemap_name", :size=>30, :value=>"New Map"}%></p>

     <%= f.fields_for :waypoints do |p| %>
    <%= p.select :waypoint, itinerary.locations_for_select,{},{ :multiple=>"true", :id=>"waypoints", :class=>"mobile-waypoints-remove"}%>   
    <% end %>
    <% end %>

For some reason, this is throwing the following error:

    ActionView::TemplateError (compile error .../maptry.html.erb:392: syntax error, unexpected ')'        
    ...ields_for :waypoints do |p| ).to_s); @output_buffer.concat ...

Thanks for any help you can offer!

FINAL WORKING VERSION FOR RAILS 2

    <% f.fields_for @waypoints do |p| %>
    <%= p.select :waypoint, {},{}, :multiple=>"true", :id=>"waypoints", :class=>"mobile-waypoints-remove" %>      
    <% end %>
Was it helpful?

Solution

You are ending you form_for before starting the nested form

Try the below code

<% form_for @newsavedmap, :html=>{:id=>'createaMap'} do |f| %>
  <%= f.error_messages %>
  <%= f.text_field :name, {:id=>"savemap_name", :size=>30, :value=>"New Map"}%></p>


<%= f.fields_for :waypoints do |p| %>
    <%= p.select :waypoint, itinerary.locations_for_select,{},{ :multiple=>"true", :id=>"waypoints", :class=>"mobile-waypoints-remove"}%>   
<% end %>
<% end %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top