Edit data using simple form for

129 Views Asked by At

I have a rails app with an index for several objects, and I've created a button to edit using a modal.

But every time I click it, it only displays the information of the first object an not the rest of them, I mean, it doesn't matter which card I clicked, it displays only the information of the first.

How can I make each card to link the edit modal to its own information?

Controller:

class DesignsController < ApplicationController
  def index
    @designs = Design.all
  end

  def new
    @design = Design.new
  end

  def create
    @design = Design.new(design_params)
    @design.save
    redirect_to designs_path
  end

  def edit
    @design = Design.find(params[:id])
  end

  def show
    @design = Design.find(params[:id])
  end

  def update
    @design = Design.find(params[:id])
    @design.update(design_params)
    redirect_to designs_path
  end

  def destroy
    @design = Design.find(params[:id])
    @design.destroy
    redirect_to designs_path
  end

  private

  def design_params
    params.require(:design).permit(:project_number, :client, :project_name, :responsable, :revision, :line, :status, :autodesk_link, :server_path)
  end

end

View:

<!-- Modal -->
        <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="staticBackdropLabel">Editar información</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">
                <%= simple_form_for(design) do |f| %>
                  <%= f.input :project_number %>
                  <%= f.input :client %>
                  <%= f.input :project_name %>
                  <%= f.input :responsable %>
                  <%= f.input :revision %>
                  <%= f.input :line %>
                  <%= f.input :status %>
                  <%= f.input :autodesk_link %>
                  <%= f.input :server_path %>
                  <%= f.submit "Guardar", class: "modal-button" %>
                <% end %>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>

              </div>
            </div>
          </div>
        </div>

1

There are 1 best solutions below

1
On

Plz Try this:

{<%= Simple_Form_For(@Designs) Do |F| %>}