0

我有一个脚手架产品和两个模型productnumbersserialnumber.

产品.rb

has_one :productnumber 
accepts_nested_attributes_for :productnumber

产品编号.rb

belongs_to :product 
has_many :serialnumbers 
accepts_nested_attributes_for :serialnumbers

序列号.rb

belongs_to :productnumber

表格显示得很好,我可以输入数据并毫无问题地创建或更新,但serialnumber根本没有保存。编辑产品时,该serialnumber字段为空白,但在创建产品时有数据。

只有productandproductnumber被保存但serialnumber不被保存。

Rails 不会给出serialnumber未保存的错误。任何帮助如何保存serialnumber它的一部分productnumber

4

1 回答 1

0
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
于 2012-06-26T10:48:38.110 回答