Я работаю над загрузкой изображений и видео в приложении rails, используя paperclip и ffmpeg.
Следующий код в models/image.rb
работает нормально:
has_attached_file :image,
processors: [:ffmpeg]
validates_attachment_content_type :image, content_type: /.*/
Но когдаЯ добавляю стилизацию в код следующим образом, он выдает ошибку (загрузка страницы):
has_attached_file :image, styles: lambda {|a| if a.instance.is_image? then {original: {}, medium: "300x300>"} end},
processors: [:ffmpeg]
validates_attachment_content_type :image, content_type: /.*/
def is_image?
return false unless @attachment_image.content_type
['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'].include?(@attachment_image.content_type)
end
Ошибка выглядит следующим образом:
F, [2018-10-04T15:04:47.381706 #9836] FATAL -- : [643e7428-d41e-4000-9a48-566d85e7b109]
F, [2018-10-04T15:04:47.381906 #9836] FATAL -- : [643e7428-d41e-4000-9a48-566d85e7b109] ActionView::Template::Error (undefined method `each_pair' for nil:NilClass):
F, [2018-10-04T15:04:47.382186 #9836] FATAL -- : [643e7428-d41e-4000-9a48-566d85e7b109] 1: insert_tag renderer_for(:show)
F, [2018-10-04T15:04:47.382345 #9836] FATAL -- : [643e7428-d41e-4000-9a48-566d85e7b109]
F, [2018-10-04T15:04:47.382441 #9836] FATAL -- : [643e7428-d41e-4000-9a48-566d85e7b109] app/admin/resorts.rb:46:in `block (5 levels) in <top (required)>'
Как я могу решить эту проблему?
Обновление
Эта ошибка отображается только при попытке загрузить видео или при загрузке страницы, содержащей видео.
Код в pp/admin/resorts.rb
, упомянутый в сообщении об ошибке, следующий (я использую камень activeadmin):
if im.itype == 'video-slider' then
video_tag im.image, class: 'my_image_size' # line 46
else
image_tag im.image, class: 'my_image_size'
end
При попытке загрузить изображение ошибка изменилась следующим образом ():
Input #0, image2, from '/tmp/dcdc7c452102ec2b9255973f59b40ee320181004-23173-fx7vzi.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 35614 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080, 25 tbr, 25 tbn, 25 tbc
[NULL @ 0x564aeb7df580] Unable to find a suitable output format for '/tmp/dcdc7c452102ec2b9255973f59b40ee320181004-23173-fx7vzi20181004-23173-zurkvx'
/tmp/dcdc7c452102ec2b9255973f59b40ee320181004-23173-fx7vzi20181004-23173-zurkvx: Invalid argument
):
F, [2018-10-04T19:13:02.028565 #23173] FATAL -- : [c267e57b-7e06-4624-be1c-0d9aa4b71e00]
F, [2018-10-04T19:13:02.028730 #23173] FATAL -- : [c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip-ffmpeg (1.2.0) lib/paperclip_processors/ffmpeg.rb:175:in `rescue in make'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip-ffmpeg (1.2.0) lib/paperclip_processors/ffmpeg.rb:171:in `make'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/processor.rb:34:in `make'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:533:in `block in post_process_style'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:532:in `each'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:532:in `reduce'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:532:in `post_process_style'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:519:in `post_process_styles'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:512:in `block (2 levels) in post_process'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/callbacks.rb:131:in `run_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/callbacks.rb:38:in `run_paperclip_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:510:in `block in post_process'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/callbacks.rb:38:in `run_paperclip_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:509:in `post_process'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:465:in `post_process_file'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/attachment.rb:113:in `assign'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] paperclip (5.2.1) lib/paperclip/has_attached_file.rb:66:in `block in define_setter'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:46:in `public_send'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:39:in `each'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activemodel (5.1.5) lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/core.rb:337:in `initialize'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/inheritance.rb:66:in `new'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/inheritance.rb:66:in `new'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activeadmin (1.1.0) lib/active_admin/resource_controller/data_access.rb:130:in `build_new_resource'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activeadmin (1.1.0) lib/active_admin/resource_controller/data_access.rb:116:in `build_resource'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] inherited_resources (1.8.0) lib/inherited_resources/actions.rb:31:in `create'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/abstract_controller/base.rb:186:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/rendering.rb:30:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/callbacks.rb:131:in `run_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/rescue.rb:20:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/notifications.rb:166:in `block in instrument'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/notifications.rb:166:in `instrument'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] searchkick (3.0.0) lib/searchkick/logging.rb:209:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/abstract_controller/base.rb:124:in `process'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionview (5.1.5) lib/action_view/rendering.rb:30:in `process'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal.rb:189:in `dispatch'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_controller/metal.rb:253:in `dispatch'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:31:in `serve'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `each'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `serve'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:844:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] warden (1.2.7) lib/warden/manager.rb:35:in `catch'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] warden (1.2.7) lib/warden/manager.rb:35:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/etag.rb:25:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/conditional_get.rb:38:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/head.rb:12:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/cookies.rb:613:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activerecord (5.1.5) lib/active_record/migration.rb:556:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] railties (5.1.5) lib/rails/rack/logger.rb:36:in `call_app'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] railties (5.1.5) lib/rails/rack/logger.rb:24:in `block in call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `tagged'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] railties (5.1.5) lib/rails/rack/logger.rb:24:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] request_store (1.4.0) lib/request_store/middleware.rb:19:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/request_id.rb:25:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/method_override.rb:22:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/runtime.rb:22:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] activesupport (5.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] actionpack (5.1.5) lib/action_dispatch/middleware/static.rb:125:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] railties (5.1.5) lib/rails/engine.rb:522:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] puma (3.11.2) lib/puma/configuration.rb:225:in `call'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] puma (3.11.2) lib/puma/server.rb:438:in `process_client'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] puma (3.11.2) lib/puma/server.rb:302:in `block in run'
[c267e57b-7e06-4624-be1c-0d9aa4b71e00] puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'