问题标签 [nested-form-for]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
350 浏览

javascript - 在 Rails 4 中,accept_nested_attributes_for 不起作用 allow_destroy 标志

allow_destroy => true 在视图中不起作用:

脚本

模型

当尝试 otredktirovat 浏览器端 yavaskrita 隐藏如何但不删除和重复记录。

为什么 accept_nested_attributes_for allow_destroy 不起作用?

由截屏视频制作 http://railscasts.com/episodes/197-nested-model-form-part-2 http://railscasts.com/episodes/196-nested-model-form-part-1

请告诉我如何与之抗争。

0 投票
0 回答
167 浏览

ruby-on-rails - 无法使 nested_form gem 工作(javascript:void(0) 错误)

这是我在这里的第一篇文章,所以请多多包涵。我正在尝试将 nested_form gem 合并到我的 Rails 应用程序中。我有一个带有许多 BadgeElements 的 Badge 模型。我希望能够动态添加和删除 BadgeElements,但我无法让 gem 正常工作。我不知道这是我的设置还是我如何调用它。(我已经在 StackOverflow 和 Google 上寻找答案,但没有任何帮助。)我在我的 Gemfile 中安装了“nested_form”gem(0.3.2),在我的应用程序中添加了“//= require jquery_nested_form”行.js,并将我的“form_for”更改为“nested_form_for”,但添加和删除的链接不起作用。当我点击它们时,我会收到一条“javascript:void(0)”消息。有人可以告诉我我做错了什么吗?

以下是相关代码位供参考:

徽章.rb:

_form.html.haml:

徽章元素/_form.html.haml:

我正在运行 Rails 4。感谢任何帮助。提前致谢!

0 投票
1 回答
782 浏览

javascript - Rails 3 - nested_form gem nested:fieldAdded appears not to triggered

I'm using the nested_form gem which works great until I try to implement a jquery call based on the github example for a nested:fieldAdded event. Here is the relevant view code:

#xA;

To to handle a "nested:fieldAdded:details" jquery call I added the following to my application.js file:

#xA;

This worked fine and I got an alert when I hit the "Add" Link. I want to check all previous detail fields and remove the selected options from the new detail field select box. Since I'm new to jquery/js I did a bit of hacking tried and added a few line of code to the app.js method I thought would accomplish my goal. They didn't work and the alert failed to trigger.

Now that I have reverted back to the original app.js method code, I still can't get the the alert to trigger. Setting breakpoints in the file with Safari and Firefox dev tools doesn't work, they never hit when I click "Add". I also cleared my browser cache and restarted the server multiple times but still cannot recreate my initial test where I got the alert to trigger. Why wouldn't the event trigger when it originally did? Any help would be greatly appreciated, thx!

0 投票
2 回答
4520 浏览

ruby-on-rails - How can I access the validation errors for my nested attributes?

Above is a snippet of my form, I can access validations for the articles i.e. validates_presence of :author, :title however I can't access the validations I set for my nested_attributes, which happen to be photos. Any ideas on how to show error messages?

0 投票
1 回答
164 浏览

ruby-on-rails-4 - has_many : 通过关联和 form_for

我第一次尝试通过关联构建一个包含 has_many 的表单,这是我的三个模型:

我的书/new.html.erb

我的books_controller.rb

我收到了这个错误:

nil:NilClass 的未定义方法“map”

我试着关注这篇文章: http ://howilearnedrails.wordpress.com/2013/12/18/rails-4-dropdown-menu-with-collection_select/

0 投票
1 回答
82 浏览

ruby-on-rails-4 - 嵌套属性和 params.require 错误

我是 ruby​​ on rails 的新手,尤其是嵌套形式。我正在尝试以相同的形式创建一个作者和一本书,知道它们之间存在多对多的关系,我的代码如下所示。书本.rb

作者.rb:

谈话.rb

book_controller.rb

书籍\new.html.erb

我得到的错误

BooksController#create 作为 HTML 参数处理:{"utf8"=>"✓", "authenticity_token"=>"qpGng8tOiC/B5VX2tphuhAe+Wq1vx7it1vEO6XmwZmI=", "book"=>{"title"=>"boooooooooooooook", "authors_attributes "=>{"0"=>{"f_name"=>"auuuuuuuuuuuuuuuuuthor"}}}, "commit"=>"Submit"} 不允许的参数:authors_attributes

0 投票
0 回答
157 浏览

ruby-on-rails - form_for 编辑操作错误

画廊控制器.rb

_form.html.erb

_photo_fields.erb

画廊.rb

照片.rb

问题是,我可以通过这个表单创建新照片,但是当我尝试编辑它们时,我得到未定义的局部变量或方法“f”。

与当地人一起编辑 解决方案有助于升技,但我仍然无法顺利运行代码。我编辑了我的代码,所以我可以看到当前上传了哪些照片,并添加了一个复选框来删除选定的照片。但是我在尝试这样做时得到了未经许可的参数:_destroy 错误。另外:当我尝试将新照片添加到现有画廊时,我在 GalleriesController#update 中得到 ActiveRecord::UnknownAttributeError。使用多张照片创建新画廊时一切正常。它与当前上传的图片有关,我创建了一个没有照片的画廊,我可以毫无问题地将它们添加到编辑操作中。

因为我没有足够的声誉直接在这里发布图片,所以我粘贴了我的编辑页面当前看起来如何的链接:http: //s13.postimg.org/3o8uvansn/Screenshot_from_2014_11_01_12_55_17.jpg

快速编辑:似乎我修复了更新问题。这条线

在 _form.html.erb 中让我上传新图片。删除时未经许可的参数的问题仍然存在。

仅删除图片上传的新文件字段,它不会删除已上传的图片。

0 投票
1 回答
1173 浏览

ruby-on-rails-4 - 带有嵌套 has_many 和 has_one 的嵌套表单

我基本上遇到了与这篇文章相同的问题,尽管我的情况略有不同:has_many 嵌套表单,其中包含 has_one 嵌套表单

但正如该帖子中的其他人所提到的,提供的答案并不能解决问题。

建立关系以便 Invoice has_many items 和每个 Item has_one 修饰符。我正在尝试制作一个 form_for Invoice,它允许使用创建许多项目,每个项目都有一个修饰符。

楷模


控制器


意见(哈姆尔)

让我们回顾一下正在发生的事情。为了构建嵌套的 has_one 关系,我在嵌套字段部分中构建了一个项目,以便我可以构建 has_one 修饰符。这是因为 rails 要求您在 has_one 关系中显式调用“build_something”(通常这在控制器的 new 中调用,但我只想在有人单击“新建项目”按钮后进行构建)。对于创建新发票,此代码完美运行。检查控制台,我看到关系已创建,我可以验证修饰符是否已成功创建。

但是,当我回去编辑发票时,cocoon 知道我已经有一个修饰符,所以它调用部分一次来为我的单个修饰符创建必要的字段。这些字段为空。不过这是有道理的,因为 cocoon 正在渲染该部分,它正在构建一个带有新修饰符的新代码并将字段设置为空白。我可以确认这是正在发生的事情,因为一旦我正确保存了我的修改器,我就可以进入我的部分,删除两个构建调用,并查看正确显示保存的修改器信息的编辑页面。

当然,现在我已经删除了构建调用,表单不再保存我创建的任何修饰符。所以本质上,我需要那里的构建调用来构建新的修饰符,但如果我想查看它们,我不能把它们放在那里。

有没有人有解决这种情况的方法?我发现了多个堆栈溢出问题,但没有一个能解决这个问题。

0 投票
0 回答
87 浏览

ruby-on-rails - 嵌套形式在参数中返回空哈希

嗨,这很奇怪我有 3 个模型

我有视图模板

但是在我的控制器中,我把所有东西都弄空了,例如

我做错了什么,deal_items_attributes 哈希中没有 deal_menu_prices_attributes。我期待这样的事情

0 投票
0 回答
135 浏览

ruby-on-rails-4 - Rails 4:如何使用 form_for (has_many :through with extra attributes)

我有一个 Store 模型、Product 模型和一个 StoreProduct 模型来在商店和产品之间形成多对多的关系。

StoreProduct 模型在 store_id 和 product_id 之上,有一个属性 price:float。

我正在努力弄清楚如何设计一个表格来创建一个给定商店的新产品。为新的 StoreProduct 对象制作一个表单会更好吗?这样做的传统方法是什么?

商店.rb


产品.rb


store_product.rb