0

足場 Product と 2 つのモデルproductnumbersとがありserialnumberます。

製品.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フィールドは空白ですが、商品が作成されたときにデータがありました。

productとのみproductnumberが保存されますが、保存され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 に答える