gpt4 book ai didi

ruby-on-rails - nested_form gem : wrong number of arguments (4 for 3)错误

转载 作者:行者123 更新时间:2023-12-03 16:12:09 30 4
gpt4 key购买 nike

我已经为这个问题苦苦挣扎了好几天,而且似乎无法弄清楚出了什么问题。我正在尝试允许模型Item属于模型Location的多态文件附件。我的路线定义为:

resources :locations do
resources :items
post :sort
end

resources :items do
resources :assets #model for attachments
end

我跟随 a tutorial一起使用carrierwave和 nested_form做到了这一点。但是,设置完所有内容后,在为 New模型请求 Item操作时出现以下错误: wrong number of arguments (4 for 3)。它告诉我该 View 的第7行出现错误:
<%= nested_form_for [@location, @item], :html => { :multipart => true } do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>

<%= f.fields_for :assets do |a_form| %> ### LINE 7 ####
<p>
<%= a_form.label :file %><br />
<%= a_form.file_field :file %>
<%= a_form.hidden_field :file_cache %>
</p>
<%= a_form.link_to_remove "Remove this attachment" %>
<% end %>

<%= f.link_to_add "Add attachment", :assets %>
<p><%= f.submit %></p>
<% end %>

如果我不使用nested_form gem并以正常的 form_for开始 View ,则不会出现任何错误,并且能够将单个文件成功附加到 Item。我可以尝试不使用gem,但据我所知,nested_form将使某些功能自动化,例如删除文件并生成ajax以添加新附件。

我只是想知道是否有人遇到了此错误,或者知道我犯了什么错误而导致nested_form问题?我知道错误的含义,只是不确定在哪里/为什么要抛出额外的参数。我非常感谢您可以提供的任何见解!

仅供引用,我的开发人员设置: rails (3.1.0,3.0.10),nested_form(0.1.1),载波(0.5.7)

最佳答案

为了使nested_form与rails 3.1一起使用,我不得不从github中获取最新版本,而不是使用gem中的内容。在我的Gemfile中:

gem "nested_form", :git => "git://github.com/ryanb/nested_form.git"

关于ruby-on-rails - nested_form gem : wrong number of arguments (4 for 3)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7541096/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com