ruby-on-rails - 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
?
谢谢
解决方案
推荐阅读
- php - 使用 PHP 转换器将 XML 转换为 CSV [图像抓取问题]
- javascript - 如何在 Vue js 中为我的头部对象使用异步函数?
- c# - C# 自动实现属性的延迟加载
- c - STM32 UART中断溢出后不起作用
- python - 如何在 Django DRF 中过滤嵌套序列化程序的字段
- delphi - 从用户到用户的网络共享链接聊天请帮助 - Delphi
- reactjs - 处理事务时出现 VM 异常:PromiEvent 中的操作码无效
- python - 我们应该对分类变量进行标准化/标准化/特征缩放吗?
- java - Java 应用程序窗口在 C# InterOp 中未被识别为 java 窗口
- sql - SELECT attribute FROM table 和 table.attribute 有什么区别?