ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

When I cleck on <%= f.link_to_add "Add a Step", :steps %>, nothing happens. #380

Closed noahsibai closed 7 years ago

noahsibai commented 7 years ago

Recipe Model class Recipe < ActiveRecord::Base has_many :ingredients, :dependent => :destroy has_many :steps, :dependent => :destroy attr_accessible :title, :prep_time, :cook_time, :servings, :origin accepts_nested_attributes_for :ingredients, :steps end

Step Model class Step < ActiveRecord::Base belongs_to :recipe attr_accessible :description, :sequence, :steps_attributes end

New View

Creating a New Recipe

<%= nested_form_for(@recipes) do |f| %> <%= render :partial=> 'form', :locals => {:f=>f} %>

<%= f.fields_for :steps, :id => 'steps' do |s| %> <%= render :partial=> 'step', :locals => {:s=>s} %> <% end %> <%= f.link_to_add "Add a Step", :steps %>
<%= f.fields_for :ingredients do |s| %> <%= render :partial => "ingredient", :locals => {:s,s} %> <% end %>

<%= f.submit %> <% end %> <%= link_to "Back", recipes_path %>

Why wont it add a new fields_for?