[英]Nested forms in rails 3 error, not saving properly
I have a scaffold Product and two models productnumbers
and serialnumber
. 我有一个支架产品,并且有两个型号
productnumbers
和serialnumber
。
Product.rb 产品.rb
has_one :productnumber
accepts_nested_attributes_for :productnumber
Productnumber.rb 产品编号
belongs_to :product
has_many :serialnumbers
accepts_nested_attributes_for :serialnumbers
serialnumber.rb 序列号
belongs_to :productnumber
The form shows up fine and I can input data and create or update without problems but the serialnumber
is not saved at all. 表单显示正常,我可以输入数据并创建或更新,没有问题,但是
serialnumber
根本没有保存。 When editing the product, the serialnumber
field is blank however it had data when the product was created. 编辑产品时,
serialnumber
字段为空白,但是在创建产品时它具有数据。
Only the product
and productnumber
are saved but serialnumber
isn't saved. 仅保存
product
和productnumber
,但不保存serialnumber
。
Rails doesn't give an error that the serialnumber
isn't saving. Rails不会给出
serialnumber
未保存的错误。 Any help how to save the serialnumber
that is part of productnumber
? 对如何保存
productnumber
一部分的serialnumber
有帮助吗?
class CustomersController < ApplicationController
# GET /customers
# GET /customers.json
def index
@customers = Customer.find(:all, :include=> [:continent, :paymethod])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @customers }
end
end
# GET /customers/1
# GET /customers/1.json
def show
@customer = Customer.find(params[:id], :include=> [:continent, :paymethod])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @customer }
end
end
# GET /customers/new
# GET /customers/new.json
def new
@customer = Customer.new
@continents = Continent.find :all
@paymethods = Paymethod.find :all
@customer.build_company
respond_to do |format|
format.html # new.html.erb
format.json { render json: @customer }
end
end
# GET /customers/1/edit
def edit
@customer = Customer.find(params[:id])
@continents = Continent.find :all
@paymethods = Paymethod.find :all
end
# POST /customers
# POST /customers.json
def create
@customer = Customer.new(params[:customer])
@continents = Continent.find :all
@paymethods = Paymethod.find :all
respond_to do |format|
if @customer.save
format.html { redirect_to @customer, notice: 'Customer was successfully created.' }
format.json { render json: @customer, status: :created, location: @customer }
else
format.html { render action: "new" }
format.json { render json: @customer.errors, status: :unprocessable_entity }
end
end
end
# PUT /customers/1
# PUT /customers/1.json
def update
@customer = Customer.find(params[:id])
respond_to do |format|
if @customer.update_attributes(params[:customer])
format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @customer.errors, status: :unprocessable_entity }
end
end
end
# DELETE /customers/1
# DELETE /customers/1.json
def destroy
@customer = Customer.find(params[:id])
@customer.destroy
respond_to do |format|
format.html { redirect_to customers_url }
format.json { head :no_content }
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.