fields_for】的更多相关文章

1 一对多 Using Strong Parameters With Fields For & Nested Forms in Rails 4 http://www.rubyexperiments.com/using-strong-parameters-with-nested-forms/ class Account < ActiveRecord::Base has_many :people accepts_nested_attributes_for :people end class Pe…
详细参考 http://railscasts.com/episodes/73-complex-forms-part-1中part-1.2.3部分 借助field_for可以生成表单来处理两个或更多模型对象的数据 先看一个官方的例子,一个表单中有person和permission两个模型,其中每个person包含一个permission <%= form_for(@person) do |person_form| %> First name: <%= person_form.text_fi…
在component表里用text类型的字段存储hash数据 (1)新建字段 ,这是migration的内容 class AddHintsToComponents < ActiveRecord::Migration[5.0] def change add_column :components, :hints, :text end end (2)controller def update if @component.update!(component_params) redirect_to @co…
自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源,深入理解下 向数据库插记录时经常会用到new, build, create.这三个方法很容易混淆 save:rails中的save其实是create_or_update,新建或修改记录!不一定是新建,切记 new :只是在内存中新建一个对象,操作数据库要调用save方法. create = new…
我的git代码:https://github.com/chentianwei411/nested_form-Stimulus- Stimulus:     https://www.cnblogs.com/chentianwei/p/9806875.html 开始: rails new -m ../jumpstart,\ Gorails视频\(创建一个rails模版\)/template.rb -d postgresql nested_forms rails webpacker:install:s…
原文 1. form_tag 1) 基础 Form <%= form_tag do %> Form contents <% end %> 生成 html <form accept-charset="UTF-8" action="/" method="post"> <input name="utf8" type="hidden" value="✓"…
嵌套表单1-1 嵌套表单1-多 选日期时间的UI (一个jquery Plugin) 拆除前后台css和js Rich Editor, 显示输入的HTML tag 批次编辑/删除 嵌套表单1-1 核心知识点:ActiveRecord Nested Attributes 嵌套属性的功能可以让你在关联的记录上保存属性,通过父记录.默认这个功能是关闭的. 使用类方法 #accepts_nested_attributes_for( :小写类名 ), 开启这个功能后,会增加一个属性存入方法, 如  pro…
Model: class Blog < ActiveRecord::Base has_many :strip_rules accepts_nested_attributes_for :strip_rules, allow_destroy: true end class StripRule < ActiveRecord::Base belongs_to :blog attr_accessible :rule, :blog_id end 要实现在新建和修改blog时可以添加/删除任意多个strip…
一个ruby on rails项目,用户和公司的模型都有地址. 我要创建一个地址表,包含用户和公司表的引用,比直接做下去要好一点,这回让我的数据库设计保持干净. 我的第一印象是,这似乎很难实现,外面所有的讨论及教程都只说明了在model如何设置,但是并没有说明在controller和view如何使用它.我好一顿放狗,也没有得到太多的帮助. 令我感到惊喜是其实在rails设置并使用多态表单是很简单的. 首先依然是先设置model结构: 01 class Company< ActiveRecord:…
自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源,深入理解下 向数据库插记录时经常会用到new, build, create.这三个方法很容易混淆 save:rails中的save其实是create_or_update,新建或修改记录!不一定是新建,切记 new :只是在内存中新建一个对象,操作数据库要调用save方法. create = new…