Я очень плохо знаком с рельсами, поэтому не знаю, что я делаю, но я пытаюсь использовать шаблон проектирования объектов формы. Я пытался отладить некоторое время и не могу понять это. Изменить: я добавил это в верхней части моего контроллера: требовать './ lib / assets / personal_trainer_from'. Теперь я получаю эту ошибку: ( неинициализированная константа PersonalTrainerForm :: Virtus ). Это форма, которую я пытаюсь использовать для базы данных
class PersonalTrainerForm
include ActiveModel::Model
include Virtus.model
attribute :firstName, String
attribute :secondName, String
attribute :desription, String
attribute :amountOfClients, Integer
attr_reader :record
def persist
@personal_trainer = id ? PersonalTrainer.find(id) : PersonalTrainer.new
if valid?
@personal_trainer.save!
true
else
false
end
end
end
Это мой файл контроллера
require './lib/assets/personal_trainer_from'
class PersonalTrainersController < ApplicationController
before_action :set_personal_trainer, only: [:show, :edit, :update, :destroy]
# GET /personal_trainers
# GET /personal_trainers.json
def index
@personal_trainers = PersonalTrainer.all
end
# GET /personal_trainers/1
# GET /personal_trainers/1.json
def show
@personal_trainer_decorator = helpers.decorate(personal_trainer)
end
# GET /personal_trainers/new
def new
@personal_trainer = PersonalTrainer.new
end
# GET /personal_trainers/1/edit
def edit
end
# POST /personal_trainers
# POST /personal_trainers.json
def create
@personal_trainer = PersonalTrainerForm.new(personal_trainer_params)
respond_to do |format|
if @personal_trainer.save
format.html { redirect_to @personal_trainer, notice: 'Personal trainer was successfully created.' }
format.json { render :show, status: :created, location: @personal_trainer }
else
format.html { render :new }
format.json { render json: @personal_trainer.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /personal_trainers/1
# PATCH/PUT /personal_trainers/1.json
def update
respond_to do |format|
if @personal_trainer.update(personal_trainer_params)
format.html { redirect_to @personal_trainer, notice: 'Personal trainer was successfully updated.' }
format.json { render :show, status: :ok, location: @personal_trainer }
else
format.html { render :edit }
format.json { render json: @personal_trainer.errors, status: :unprocessable_entity }
end
end
end
# DELETE /personal_trainers/1
# DELETE /personal_trainers/1.json
def destroy
@personal_trainer.destroy
respond_to do |format|
format.html { redirect_to personal_trainers_url, notice: 'Personal trainer was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_personal_trainer
@personal_trainer = PersonalTrainer.find(params[:id])
end
# Only allow a list of trusted parameters through.
def personal_trainer_params
params.require(:personal_trainer).permit(:firstName, :secondName, :desription, :amountOfClients)
end
end
И, наконец, это полный след.
** app / controllers / personal_trainers_controller.rb: 30: в create'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in
send_action 'actionpack (6.0.2.1) lib / abstract_controller / base.rb: 196: в process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in
process_action' actionpack (6.0.2.1) lib / abstract_controller / callbacks.rb: 42: в block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in
пакет действий run_callbacks (6.0.2.1) lib / abstract_controller / callbacks.rb: 41: в process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in
process_action 'пакет действий (6.0.2.1) lib / action_controller / metal / instrumentation.rb: 33: в блоке block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in
в инструменте 'activesupport (6.0.2.1) lib / active_support / notifications / instrumenter.rb: 24: в instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in
инструменте' пакет действий (6.0.2.1) lib / action_controller / metal / instrumentation.rb: 32: в process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in
process_action 'activerecord (6.0.2.1) lib / active_record / railties / controller_runtime.rb: 27: в process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in
процесс' actionview (6.0.2.1) lib / action_view / render.rb: 39: in process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in
dispatch 'actionpack (6.0.2.1) lib / action_control ler / metal.rb: 252: в dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in
dispatch 'actionpack (6.0.2.1) lib / action_dispatch / routing / route_set.rb: 33: в serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in
блок в serve' actionpack (6.0.2.1) lib / action_dispatch / trip / router.rb: 32: в each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in
serve 'actionpack (6.0.2.1) lib / action_dispatch / routing / route_set.rb: 837: в call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in
call' remotipart (1.4.4) lib / remotipart / middleware. rb: 32: в call'
warden (1.2.8) lib/warden/manager.rb:36:in
блоке в call 'warden (1.2.8) lib / warden / manager.rb: 34: в catch'
warden (1.2.8) lib/warden/manager.rb:34:in
call' rack (2.2.2) lib / rack / tempfile_reaper.rb: 15: в call'
rack (2.2.2) lib/rack/etag.rb:27:in
call 'rack (2.2.2) lib / rack / conditional_get.rb: 40: в call'
rack (2.2.2) lib/rack/head.rb:12:in
call' actionpack (6.0.2.1) lib / action_dispatch / http / content_security_policy.rb: 18: в call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in
context 'rack (2.2.2) lib / rack / session / abstract / id.rb: 260: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in
вызов' activerecord (6.0.2.1) lib / active_record /igration.rb: 567: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in
блок в call 'activesupport (6.0.2.1) lib / active_support / callbacks.rb: 101: in run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in
call' actionpack (6.0.2.1) lib / action_dispatch / middleware / executor.rb: 14: in call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in
call 'actionpack ( 6.0.2.1) lib / action_dispatch / middleware / debug_exceptions.r b: 32: в веб-консоли call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in
call_app (4.0.1) lib / web_console / middleware.rb: 28: в веб-консоли block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in
catch '(4.0.1) lib / web_console / middleware.rb: 17: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in
call 'railties (6.0.2.1) lib / rails / rack / logger.rb: 38: в call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in
блоке в call' activesupport (6.0.2.1) lib / active_support / tagged_logging.rb: 80: в block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in
с тегом 'activesupport (6.0.2.1) lib / active_support / tagged_logging.rb: 80: в tagged'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in
вызов' sprockets-rails (3.2.1) lib / sprockets / rails / quiet_assets.rb: 13: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in
call 'actionpack (6.0.2.1) lib / action_dispatch / middleware / request_id.rb: 27: в call'
rack (2.2.2) lib/rack/method_override.rb:24:in
вызов' rack (2.2.2) lib / rack / runtime.rb: 22: в call'
activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in
call ' actionpack (6.0.2.1) lib / action_dispatch / middleware / executor.rb: 14: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in
call 'rack (2.2.2) lib / rack / sendfile.rb: 110: в call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in
call' webpacker (4.2. 2) lib / webpacker / dev_server_proxy.rb: 23: в perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in
call 'railties (6.0.2.1) lib / rails / engine.rb: 526: в call'
puma (4.3.1) lib/puma/configuration.rb:228:in
call' puma (4.3.1) lib / puma / server.rb: 681: в handle_request'
puma (4.3.1) lib/puma/server.rb:472:in
process_client 'puma (4.3.1) lib / puma / server.rb: 328: в block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in
блоке в spawn_thread' ** Если есть кто-то, кто может направить меня в правильном направлении, это будет высоко ценится.