0

저는 비계 제품과 두 모델 productnumbersserialnumber을 가지고 있습니다.레일 3의 중첩 된 양식 오류, 제대로 저장하지 않음

Product.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 

형태가 잘 보여 문제없이 I 수있는 입력 데이터 생성하거나 업데이트 serialnumber은 전혀 저장되지 않습니다. 제품을 편집 할 때 serialnumber 필드는 비어 있지만 제품을 만들 때 데이터가 있습니다.

productproductnumber 만 저장되지만 serialnumber은 저장되지 않습니다.

레일즈는 serialnumber이 저장되지 않는다는 오류를주지 않습니다. productnumber의 일부인 serialnumber을 저장하는 방법에 대한 도움이 필요하십니까?

+4

양식에 대한보기 코드와 컨트롤러에서 작성 작업을 표시하십시오. –

+0

@BenMiller, 나는 stackoverflow에 처음이다. 사실 문제는 해결되었지만, 지금 나는 컨트롤러 모델과 폼을 업로드 할 새로운 prob를 가지고있다. – Meow

+0

attr_accessible을 모델에 추가하는 것을 잊지 않았다? –

답변

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 
+0

소스 코드에 대한 설명을 제공해주십시오. –

관련 문제