jeudi 21 janvier 2016

Rails - Updating product actually destroys it

I am new to Rails and was creating a demo web shop app for study. I could create the products smoothly, both via rails console and by the url localhost:300/products/new. My problem is when I want to update them. I have _form.html.erb partial getting rendered both in new.html.erb and edit.html.erb

In /products/id/edit though the button "Update Product" is actually destroying the product instead of updating it

This is the _form.htlm.erb:

  <%= form_for(@product) do |f| %>
    <% if @product.errors.any? %>
       <div id="error_explanation">
        <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>

        <ul>
            <% @product.errors.full_messages.each do |message| %>
            <li><%= message %></li>
            <% end %>
        </ul>
</div>
<% end %>
<div class="row">
    <div class="col-sm-4 col-xs-12">
        <div class="field">
                <%= f.label :name %><br>
                <%= f.text_field :name, :class => "input-group input-group-sm" %>
        </div>
        <div class="field">
                <%= f.label :description %><br>
                <%= f.text_area :description %>
        </div>
        <div class="field">
                <%= f.label :image_url %><br>
                <%= f.text_field :image_url %>
        </div>
        <div class="field">
                <%= f.label :color %><br>
                <%= f.text_field :color %>
        </div>
        <div class="actions">
                <%= f.submit %>
        </div>
    </div>
</div>


Please tell me if you need more data Thanks, Anna

Aucun commentaire:

Enregistrer un commentaire