Итак, у меня есть несколько моделей в моем приложении, и все они зарегистрированы в ActiveAdmin. Все они работают отлично, кроме одного, и я не могу понять, почему. Я продолжаю получать ту же ошибку:
NameError at /admin/reports неинициализированная константа Report::Users
Модель, на которой это происходит, называется Report
class Report < ActiveRecord::Base
belongs_to :users
belongs_to :cars
enum reason: [:accident,:totaled,:stolen]
validates :reason, presence:true
end
Контроллер выглядит так:
Class ReportsController < ApplicationController
before_action :authenticate_user!
def create
@car=Car.find(params[:car_id])
@[email protected](report_params)
@report.user_id=current_user.id
@[email protected]
if @report.save
redirect_to car_path(car)
else
render 'new'
end
end
def destroy
@report=Report.find(params[:id])
@report.destroy
end
private
def report_params
params.require(:report).permit(:reason)
end
end
Это миграция, используемая для создания модели:
class CreateReports < ActiveRecord::Migration
def change
create_table :reports do |t|
t.references :user, index: true
t.references :car, index: true
t.integer :reason, default: 0
t.timestamps null: false
end
add_foreign_key :reports, :users
add_foreign_key :reports, :cars
end
end
Наконец, вот приложение active_admin/admin/report.rb:
ActiveAdmin.register Report do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# permit_params :list, :of, :attributes, :on, :model
#
# or
#
# permit_params do
# permitted = [:permitted, :attributes]
# permitted << :other if resource.something?
# permitted
# end
end
Я пытался понять это в течение нескольких часов. Решения, которые я видел на SO, не работают. Я запустил rails generate active_admin:resource Report
, чтобы создать его, чтобы он был единственным. Почему ведет себя неправильно?