2016-12-30 8 views
0

フォームを使用してrails sqliteデータベースに製品情報を追加しようとしています。私はユーザーを追加することができますが、ストアの製品は追加できません。これがフォームです。レールをデータベースに追加

<form action='/products/create' method="post"> 
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>"> 
<label>Name: 
    <input type="text" name="product"> 
</label> 
<label>Amount: 
    <input type="number" name="amount"> 
</label> 
<center><input type="submit" value="Sell"></center> 
</form> 

エラーは発生しませんが、dbに保存されません。 Products_controllerは

def create 
    @products = Product.new(name: params[:name], amount: params[:amount]) 
    if @products.valid? 
    @products.save 
    flash[:message] = "New product added" 
    redirect_to "/users" 
    else 
    flash[:errors] = @products.errors.full_messages 
    redirect_to "/products" 
    end 

答えて

0

私はそれを理解しました。問題はこの行でした。

<input type="text" name="name"> 

私のデータベース製品は、名前と量として定義されています。製品には製品フィールドがありません。

関連する問題