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 Person < ActiveRecord::Base belongs_to :account end class AccountsController < ApplicationController def new @account = Account.new @account.people.build (一对多这样写) http://www.tuicool.com/articles/Jjee6v (rails 中 create, new, build, save 的用法) @account.build_people (一对一这样写) end def create @account = Account.new(new_account_params) if @account.save respond_to do |format| format.html { redirect_to root_path, notice: "Account created successfully." } end end end private def new_account_params params.require(:account).permit( :id, :name, people_attributes: [:id, :email, :password, :password_confirmation] ) end end <% form_for @accountdo |f| %> <%= f.text_field :name %> <% f.fields_for :people do |pf| %> #注意这里 <%= pf.text_field :email %> <% end %> <% end %>
fields_for的更多相关文章
- rails中一个窗体多个模型——fields_for
详细参考 http://railscasts.com/episodes/73-complex-forms-part-1中part-1.2.3部分 借助field_for可以生成表单来处理两个或更多模型 ...
- 使用text存储hash类型的数据 Use text filed to store the hash map
在component表里用text类型的字段存储hash数据 (1)新建字段 ,这是migration的内容 class AddHintsToComponents < ActiveRecord: ...
- rails 中 create, new, build, save 的用法以及误区汇总
自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源 ...
- 动态嵌套form,使用Stimulus Js库(前后端不分离)
我的git代码:https://github.com/chentianwei411/nested_form-Stimulus- Stimulus: https://www.cnblogs.co ...
- rails 杂记 - erb 中的 form_helper
原文 1. form_tag 1) 基础 Form <%= form_tag do %> Form contents <% end %> 生成 html <form ac ...
- Rails-Treasure chest2 嵌套表单;
嵌套表单1-1 嵌套表单1-多 选日期时间的UI (一个jquery Plugin) 拆除前后台css和js Rich Editor, 显示输入的HTML tag 批次编辑/删除 嵌套表单1-1 核心 ...
- rails中accepts_nested_attributes_for应用
Model: class Blog < ActiveRecord::Base has_many :strip_rules accepts_nested_attributes_for :strip ...
- Polymorphic form--多态表单
一个ruby on rails项目,用户和公司的模型都有地址. 我要创建一个地址表,包含用户和公司表的引用,比直接做下去要好一点,这回让我的数据库设计保持干净. 我的第一印象是,这似乎很难实现,外面所 ...
- rails 中 create, new, build, save 的用法以及误区汇总 (转)
自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源 ...
随机推荐
- Loadrunner中对中文进行UTF-8转码的探索
上一篇 / 下一篇 2010-02-22 15:20:28 查看( 2378 ) / 评论( 2 ) / 评分( 5 / 0 ) 这是一个HTTP接口测试中经常会碰到的问题,目前的服务器采用的都是U ...
- .aspx 页面引用命名空间
一.单个页面引用: <%@ Import Namespace="" %> 二.所有页面引用,Web.config配置如下: <system.web> < ...
- DevOpsDays 活动咨询网站
站点:http://www.41huiyi.com/event-1452630998.html
- Security Testing Basics
Security Testing BasicsSoftware security testing is the process of assessing and testing a system to ...
- tomcat 使用log4j进行日志切割
因为tomcat catalina.out日志不会自己主动切割, 一.日志切割所需包在附近中 1. 压缩包中有三个jar包: log4j-1.2.16.jar tomcat-juli ...
- explicit 和 implicit 的用法
explicit 和 implicit 属于转换运算符,如用这两者可以让我们自定义的类型支持相互交换 explicti 表示显式转换,如从 A -> B 必须进行强制类型转换(B = (B)A) ...
- shell学习五十七天----linux任务管理,针对上一讲的总结和扩展
linux任务管理 在linux下有两类任务管理,各自是一次性和周期性.一次性是at和batch,周期性又分为系统不论什么和用户任务. 一次性任务: 1.命令格式:at [选项] time 2.选项: ...
- 把flask部署到服务器
1.新建一个wsgi.py文件 # -*- coding:utf-8 -*- import sys from os.path import abspath from os.path import di ...
- php扩展安装phpize
安装php(fastcgi模式)的时候,常常有这样一句命令:/usr/local/webserver/php/bin/phpize 一.phpize是干嘛的? phpize是什么东西呢?php官方的说 ...
- LR报错 No buffer space available Try changing the registry value 端口号不够用了
报错:Action.c(6): Error -27796: Failed to connect to server "10.16.137.8:10035": [10055] No ...