我想要实现嵌套形式使用茧宝石。
没有错误,但是当我单击item链接来编辑并触发它时,没有任何工作。但是,URL从http://127.0.0.1:3000/portfolios/2/edit到http://127.0.0.1:3000/portfolios/2/edit#。
我希望输入标记会显示出来,但它不会显示。
视图
_form.html.erb
<div class="form-group mb-3">
<h2>Technologies used: </h2>
<div>
<%= form.fields_for :technologies do |technology_form|%>
<%= render 'technology_fields', f: technology_form %>
<% end %>
<div>
<%= link_to_add_association 'Add Technology', form, :technologies %>
</div>
</div>
</div>
_technolog_fields.html.erb
<div class="form-group mb-1 nested-fields">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
模型
投资组合模型
class Portfolio < ApplicationRecord
has_many :technologies
accepts_nested_attributes_for :technologies,
reject_if: ->(attrs) { attrs['name'].blank? }
end
我在Gemfile中添加了茧宝石并运行了包安装。
我在application.js中添加//=需要茧
当我点击add技术时,什么都不会发生。
我会感谢你的帮助。
谢谢。
发布于 2022-03-31 11:16:31
您在Rails 7中使用importmap映射吗?如果是这样的话,那么您需要改变包含JS的方式。
首先在你的航站楼你会:
./bin/importmap pin @nathanvda/cocoon
然后,在你的JS的某个地方你会:
import "@nathanvda/cocoon"
PS -您还需要引入jQuery,要么通过gem,要么再次使用导入映射。
https://stackoverflow.com/questions/71645732
复制相似问题