Tag: 茧gem

创建新配方时,cocoon gem属性不会保存

在mackenziechild-recipe_box的第3周,我遇到了一些关于Cocoon的问题。 我已经安装了设备,当我创建一个新Recipe时,我的ingredients和directions属性没有被保存。 但是当我更新现有Recipe ,一切都很好。 错误消息是: 配料配方必须存在,方向配方必须存在 我究竟做错了什么? 我正在使用rails 5 应用程序/模型/ recipe.rb class Recipe :all_blank, :allow_destroy => true accepts_nested_attributes_for :directions, :reject_if => :all_blank, :allow_destroy => true end 应用程序/控制器/ recipes_controller.rb def new @recipe = Recipe.new @recipe = current_user.recipes.build end def create @recipe = Recipe.new(recipe_params) @recipe = current_user.recipes.build(recipe_params) if @recipe.save # show a success flash message and redirect […]

无法破坏现有的嵌套关联

我有三个型号: class Answer [:update] accepts_nested_attributes_for :linked_sources, reject_if: :all_blank end class Answer::LinkedSource :nested attr_accessor :nested accepts_nested_attributes_for :source, reject_if: :all_blank, allow_destroy: true end class Source < ActiveRecord::Base SOURCE_TYPES = %w(book film) has_many :linked_sources, class_name: 'Answer::LinkedSource' has_many :answers, through: :linked_sources validates :source_type, inclusion: {in: SOURCE_TYPES} validates :source_type, :title, presence: true end 我有一个表单,其中包含已存在的两个嵌套已存在的链接源+源。 在我的_linked_source_fields部分我有link_to_remove_association并且它正常工作,将“_destroy”输入的值设置为“1”。 当我删除两个资源并按下提交按钮时,我会发送以下表单数据: utf8:✓ _method:put authenticity_token:726c1e7NIb0Je2uUZYeKLXmqgFHxgakfcF6fzpjFb38= answer[theme_id]:2 […]