rails adding to database

42 views Asked by At

I am attempting to add product information to a rails sqlite database through a form. I can get users to be added but not the products for the store. This is the form.

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

It does not throw an error but it does not save to db either. Products_controller is

 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
1

There are 1 answers

0
FileasFogg On

I figured it out. The problem was this line.

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

In my database product is defined as name and amount. Product does not have a product field.