ActiveRecord :: RecordNotFound в ProducersController # edit - PullRequest
0 голосов
/ 08 мая 2020

Я получаю сообщение об ошибке в моем приложении Rails 6, которое использует Pundit для авторизации. Ошибка возникает при переходе к действию Producers # Edit (производители вложены в острова) и выдает мне ошибку al oop ..

:

ActiveRecord::RecordNotFound in ProducersController#edit
Couldn't find Producer with 'id'=15 [WHERE "producers"."island_id" = $1]

routes.rb :

Rails.application.routes.draw do
  devise_for :users
  root to: 'islands#index'
  resources :islands do
    resources :producers
  end
end

productions.controller.rb

class ProducersController < ApplicationController
  skip_before_action :authenticate_user!, only: [ :index ]
  before_action :set_island
  before_action :set_producer, only: [ :show, :edit, :update, :destroy]

...

  def edit
  end

  def update
    if @producer.save!
      redirect_to island_producer_path, notice: "Edits saved!"
    else
      render :edit
    end
  end

  private

  def set_island
    @island = Island.find(params[:island_id])
  end

  def set_producer
    @producer = @island.producers.find(params[:id])
    authorize @producer
  end

  def producer_params
    params.require(:producer).permit(:producer_name, :email, :address1, :address2, :postal_code, :city, :country)
  end
end

производители / шоу. html .erb:

      <div class="container">
        <h2><%= @producer.producer_name %></h2>
        <div class="container">
          <p><%= @producer.city %></p>
        </div>
        <% if policy(@producer).edit? %>
          <%= link_to "EDIT", edit_island_producer_path(@island, @producer), {class: "btn btn-primary"} %>
        <% end %>
      </div>
...