2016-01-21 65 views
0

我試圖保存來自窗體的輸入,並且出於某種原因它無法保存 - 並且在我的控制檯中沒有出現錯誤,也沒有在調用錯誤通知時形成。無法保存,具有嵌套的屬性並且沒有錯誤

我的形式如下:

<%= simple_form_for @line_item do |f| %> 
     <%= f.input :product_id, as: :hidden, input_html: { value: @product.id } %>  
     <% @attribute_categories.each do |category| %> 
     <%= f.simple_fields_for :line_item_attributes do |attributes_form| %> 
      <%= attributes_form.association :product_attribute, collection: category.product_attributes, label: category.name %> 
     <% end %> 
     <% end %> 

     <%= f.input :instruction %> 

     <%= f.button :submit %> 
    <% end %> 

和我創建的行動看起來像這樣:

def create 
    #product = Product.find(params[:product_id]) 
    #@line_item = @cart.add_product(product.id) 
    @line_item = @cart.line_items.new(line_item_params) 
    respond_to do |format| 
     if @line_item.save 
     format.html { redirect_to store_url(product.store), notice: 'Line item was successfully created.' } 
     # format.js { @current_item = @line_item } 
     format.json { render :show, status: :created, location: @line_item } 
     else 
     format.html { render :new } 
     format.json { render json: @line_item.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

在我的新動作我有

def new 
    @product = Product.find_by(params[:product_id]) 
    @attribute_categories = @product.attribute_categories 
    @line_item = LineItem.new 
    @line_item.line_item_attributes.build 
    respond_to do |format| 
     format.js 
    end 
    end 

和我new.js.erb渲染包含表單的引導程序模式。爲new.js.erb的代碼是:

$('body').append("<%= escape_javascript render('line_items/new_modal') %>"); 
$('#product-modal').modal('show'); 
+0

首先,您應該檢查參數值是否從您的窗體傳遞到控制器,當你點擊提交,所以,你是否嘗試使用調試器單擊提交後檢查控制檯參數值? –

回答

0

確保line_item_params是允許所有適當的PARAMS讓你能夠保存你的對象。

def line_item_params 
    params.require(:line_item).permit(:all, :the, :params, :you, :are, :passing) 
    end