1

我想向我的父模型添加和删除模型。一切正常,只是添加和删除按钮不起作用。将鼠标悬停在添加链接时会显示 javascript:void(o)。

下面是我的代码,

_form.html.erb

<%= nested_form_for @post do |f| %>
<%= f.error_messages %> 
<%= f.fields_for :stops do |task_form| %>
<%= task_form.text_field :address %>
<%= task_form.link_to_remove "Remove this task" %>
<% end %>
<%= f.link_to_add "Add a stop", :stops %></p>
<p><%= f.submit %>
<% end %>

post.rb

has_many :stops    
accepts_nested_attributes_for :stops, :reject_if => lambda { |a| a[:address].blank? }, :allow_destroy => true

post_controller

def new
@post = Post.new
@post.stops.new
end

如果有人能帮我欢呼,我会很感激

4

0 回答 0