【发布时间】:2013-06-05 11:50:33
【问题描述】:
我有一个来自用户的表单
<%= form_for(@user) do |f| %>
<%= f.fields_for :businesses do |field| %>
<div class="field">
<%= field.label :address %>
<%= field.text_field :address %>
</div>
<div class="field">
<%= field.label :city %>
<%= field.text_field :city %>
</div>
<% end %>
<% end %>
它不显示我的字段,但是当我将businesses 更改为business 时,它会显示,或者如果我从f.fields_for 中删除f。但我认为它不能正确保存到数据库中。
我的用户模型
class User < ActiveRecord::Base
has_many :businesses
accepts_nested_attributes_for :businesses
en
我的商业模式
class Business < ActiveRecord::Base
attr_accessible :user_id, :address, :city
belongs_to :user
end
我的业务迁移
class CreateBusinesses < ActiveRecord::Migration
def change
create_table :businesses do |t|
t.integer :user_id
t.string :address
t.string :city
t.timestamps
end
end
end
关于我做错了什么有什么建议吗?
谢谢
【问题讨论】:
-
该用户有业务吗?
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 nested-attributes