Я получаю следующую ошибку из приложения Rails:
URI :: GID :: MissingModelIdError в обработке
Невозможно создать глобальный идентификатор для лечения без идентификатора модели.
globalid (0.4.1) lib/global_id/uri/gid.rb:167:in `validate_model_id'
globalid (0.4.1) lib/global_id/uri/gid.rb:151:in `set_model_components'
globalid (0.4.1) lib/global_id/uri/gid.rb:136:in `check_path'
/Users/josh/.asdf/installs/ruby/2.5.1/lib/ruby/2.5.0/uri/generic.rb:819:in `path='
/Users/josh/.asdf/installs/ruby/2.5.1/lib/ruby/2.5.0/uri/generic.rb:193:in `initialize'
/Users/josh/.asdf/installs/ruby/2.5.1/lib/ruby/2.5.0/uri/generic.rb:138:in `new'
/Users/josh/.asdf/installs/ruby/2.5.1/lib/ruby/2.5.0/uri/generic.rb:138:in `build'
globalid (0.4.1) lib/global_id/uri/gid.rb:92:in `build'
globalid (0.4.1) lib/global_id/uri/gid.rb:68:in `create'
globalid (0.4.1) lib/global_id/global_id.rb:15:in `create'
globalid (0.4.1) lib/global_id/identification.rb:8:in `to_global_id'
activestorage (0.1) lib/active_storage/attached/one.rb:5:in `attachment'
activestorage (0.1) lib/active_storage/attached/one.rb:13:in `attached?'
app/views/treatments/_form.html.erb:52:in `block in _app_views_treatments__form_html_erb___357661333339907035_70285432864960'
actionview (5.1.6) lib/action_view/helpers/capture_helper.rb:39:in `block in capture'
actionview (5.1.6) lib/action_view/helpers/capture_helper.rb:203:in `with_output_buffer'
actionview (5.1.6) lib/action_view/helpers/capture_helper.rb:39:in `capture'
actionview (5.1.6) lib/action_view/helpers/form_helper.rb:450:in `form_for'
app/views/treatments/_form.html.erb:1:in `_app_views_treatments__form_html_erb___357661333339907035_70285432864960'
actionview (5.1.6) lib/action_view/template.rb:157:in `block in render'
activesupport (5.1.6) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.1.6) lib/action_view/template.rb:352:in `instrument_render_template'
actionview (5.1.6) lib/action_view/template.rb:155:in `render'
actionview (5.1.6) lib/action_view/renderer/partial_renderer.rb:342:in `block in render_partial'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'
actionview (5.1.6) lib/action_view/renderer/partial_renderer.rb:331:in `render_partial'
actionview (5.1.6) lib/action_view/renderer/partial_renderer.rb:310:in `render'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (5.1.6) lib/action_view/helpers/rendering_helper.rb:35:in `render'
app/views/treatments/new.html.erb:42:in `_app_views_treatments_new_html_erb___2682657173693281074_70285432951520'
actionview (5.1.6) lib/action_view/template.rb:157:in `block in render'
activesupport (5.1.6) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.1.6) lib/action_view/template.rb:352:in `instrument_render_template'
actionview (5.1.6) lib/action_view/template.rb:155:in `render'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:52:in `block (2 levels) in render_template'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionview (5.1.6) lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:51:in `block in render_template'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:50:in `render_template'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.1.6) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.1.6) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (5.1.6) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
actionpack (5.1.6) lib/abstract_controller/rendering.rb:24:in `render'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/josh/.asdf/installs/ruby/2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (5.1.6) lib/action_controller/metal/implicit_render.rb:33:in `default_render'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.6) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
Я получаю эту ошибку, когда пытаюсь загрузить метод new
или create
.
def new
@treatment = Treatment.new
end
def create
@treatment = Treatment.create!(treatment_params)
if @treatment.save
redirect_to root_path, notice: "Treatment added successfully"
else
render 'new', notice: "Oh no, Zuber u silly man!"
end
end
Ошибка генерируется гемом Global ID
Кажется, проблема с переменной @treatment
. При попытке использовать это в представлении я получаю сообщение об ошибке, но также и при попытке сохранить данные в базе данных.
Модель выглядит следующим образом (не знаю, почему существует 6 отдельных изображений, а не много):
class Treatment < ApplicationRecord
extend FriendlyId
friendly_id :link, use: :slugged
validates :speciality,:link,:price,:duration,:image, presence: true
validates :content, presence: true, length: { minimum: 15}
has_one_attached :image
has_one_attached :image1
has_one_attached :image2
has_one_attached :image3
has_one_attached :image4
has_one_attached :image5
has_one_attached :image6
end
И схема:
create_table "treatments", force: :cascade do |t|
t.string "category"
t.string "speciality"
t.text "content"
t.integer "price"
t.string "duration"
t.string "link"
t.string "image"
t.string "image1"
t.string "image2"
t.string "image3"
t.string "image4"
t.string "image5"
t.string "image6"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.index ["slug"], name: "index_treatments_on_slug", unique: true
end
Я довольно новичок в Rails и смотрю на это от имени друга, который еще новее, и я не знаю, что он мог или не мог сделать ранее, чтобы вызвать ошибку.
Я надеюсь, что кто-то может помочь, после нескольких часов поиска я не смог найти ничего полезного.
Спасибо!
EDIT:
Я думаю, что это как-то связано с Active Storage, как будто я пытаюсь использовать @treatments.image.attached?
в представлении, я получаю ошибку, но если используется только @treatments.image
, то ошибки нет.