Mat*_*eil 4 forms nested has-many formtastic cocoon-gem
我试图使用cocoon嵌套ajax形式加上formtastic
我的rails版本
Rails 3.2.3
Run Code Online (Sandbox Code Playgroud)
我把gem"cocoon"放到我的gemfile中并进行了捆绑安装
然后在我的元素/ _form.html.erb中:
<%= semantic_form_for @element do |f| %>
<%= f.inputs do %>
<%= f.input :projects, :label_method => :projectname%>
<%= f.semantic_fields_for :experiments do |exp| %>
<% render 'experiment_fields', :f => exp %>
<%= link_to_add_association "Add experiment", f, :experiments%>
<%end%>
<% end %>
<%= f.actions :submit, :cancel %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
with elements/_experiment_fields.html.erb:
<div class='nested-fields'>
<%= f.input :exptype %>
<%= link_to_remove_association "remove experiment", f %>
</div>
Run Code Online (Sandbox Code Playgroud)
这不会产生任何错误,但不会显示嵌套的链接或表单
然后我添加到assets/application.js:
//= require cocoon
Run Code Online (Sandbox Code Playgroud)
以及layout/application.html.erb
<%= javascript_include_tag :cocoon %>
Run Code Online (Sandbox Code Playgroud)
这会产生错误:
couldn't find file 'cocoon'
Run Code Online (Sandbox Code Playgroud)
我错过了茧安装的东西吗?有人可以帮忙吗?
The*_* GS 11
在重新启动我的rails服务器之前,在将// = require cocoon添加到资产管道后,我刚收到此错误.显然你可能已经重新启动了rails服务器,但是为了其他任何有此错误的人,请尝试重新启动rails.