我是 rad rails 的新手。我想从一种形式同时写在两个表中。
我有一个表机器(以 nom 和 role 作为列)和一个表 ipvfour(以 machine_id 和 ip 作为列)。
因此,我在模型中创建了“has-and-belongs-to-many”关系。
但是当我尝试添加一台新机器时,如果失败了
未知属性:ip
我真的不明白为什么,有人可以帮助我吗?
机器控制器:
def create @machine = Machine.new(params[:machine])
ipvfour = @machine.ip.create(params[:ip])
respond_to do |format|
if @machine.save && ipvfour.save
flash[:notice] = 'Machine was successfully created.'
format.html { redirect_to(@machine) }
format.xml { render :xml => @machine, :status => :created, :location => @machine }
别的
format.html { 渲染 :action => "new" }
format.xml { 渲染 :xml => @machine.errors, :status => :unprocessable_entity }
结尾
结尾
结尾
new.html.erb(机器)
新机
'form', :locals => { :f_machine => f_machine } %>
_form.html.erb(机器)
<% f_machine.fields_for :ip do |f_ip| %> <%= 渲染 :partial => 'ipvfours/form', :locals => { :f_ip => f_ip } %>
<% end %>
_form.html.erb (ipvfours)
<%= f_ip.label :ip %><br />
<%= f_ip.text_field :ip %>
添加机器的页面正确显示所有字段,但似乎由于...而在数据库中写入失败。我希望有人能够帮助我。
提前致谢。