首页 > 解决方案 > Rails:将嵌套属性传递给 vue.js

问题描述

我有一个调查模型

class Survey < ApplicationRecord
    has_many :questions, dependent: :destroy
    accepts_nested_attributes_for :questions, allow_destroy: true
    belongs_to :user
end

嵌套到“调查”的Quesiton模型如下;

class Question < ApplicationRecord
    enum qtype: [:multiple_choice, :check_boxes, :short_answer]
  belongs_to :survey
  has_many :options
  accepts_nested_attributes_for :options, allow_destroy: true
end

并且选项模型以嵌套方式连接到问题。

 class Option < ApplicationRecord      
      belongs_to :question 
    end

我的参数surveys_controller

def survey_params
      params.require(:survey).permit(:name, questions_attributes:[:id, :title, :qtype, :_destroy, options_attributes:[:id, :otext, _destroy]])
    end

在没有 Vue.js 实现的情况下工作很清楚。我想使用 vue.js 来制作动态表单。all nested attributes如果不使用' 'gem,我应该怎么做传递表格,我应该用gon哪个json文件创建jbuilder

谢谢

标签: ruby-on-railsrubyvue.jswebpack

解决方案


推荐阅读