Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 error with CarrierWave multiple file uploader #3070

Closed
Masaokb opened this issue Sep 24, 2018 · 3 comments
Closed

500 error with CarrierWave multiple file uploader #3070

Masaokb opened this issue Sep 24, 2018 · 3 comments
Milestone

Comments

@Masaokb
Copy link

Masaokb commented Sep 24, 2018

Hello, I really appreciate your development of great gem!

I have an issue occurring with CarrierWave multiple file uploader column (named as Topic#images )

Started GET "/topic/3/edit" for 127.0.0.1 at 2018-09-25 01:06:40 +0900
Processing by RailsAdmin::MainController#edit as HTML
  Parameters: {"model_name"=>"topic", "id"=>"3"}
  Topic Load (0.8ms)  SELECT  `topics`.* FROM `topics` WHERE `topics`.`id` = 3 ORDER BY `topics`.`id` ASC LIMIT 1
  ↳ vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
  Rendering vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_field.html.haml (1.8ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_field.html.haml (0.2ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_field.html.haml (0.5ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_field.html.haml (0.3ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_text.html.haml (3.1ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (7.2ms)
  Rendered vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (53.4ms)
Completed 500 Internal Server Error in 88ms (ActiveRecord: 0.8ms)
ActionView::Template::Error (undefined method `identifier' for #<CarrierWave::Storage::Fog::File:0x00007fc940a38188>):
     6:         %i.icon-white.icon-trash
     7:         = I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase} ##{i + 1}"
     8:
     9:     = form.check_box(field.delete_method, {multiple:true, style: 'display:none;'}, attachment.delete_key, nil)
    10:
    11: = form.file_field(field.name, field.html_attributes.reverse_merge({ data: { :"multiple-fileupload" => true }, multiple: true }))
    12:

vendor/bundle/ruby/2.5.0/gems/rails_admin-1.4.1/lib/rails_admin/config/fields/types/multiple_carrierwave.rb:16:in `block in <class:CarrierwaveAttachment>'

Gem versions

ruby '2.5.1'
rails (5.2.1)
rails_admin (1.4.1)
carrierwave (1.2.3)
mini_magick (4.8.0)
fog-aws (3.0.0)

Thank you.

@tostasqb
Copy link

I'm getting something very similar. It does not seem to be related with CarrierWave but it did start breaking after changing has_one_attached by has_many_attached with ActiveSupport

Processing by RailsAdmin::MainController#edit as HTML
  Parameters: {"model_name"=>"product", "id"=>"7"}
  Product Load (0.2ms)  SELECT  "products".* FROM "products" WHERE "products"."id" = ? ORDER BY "products"."id" DESC LIMIT ?  [["id", 7], ["LIMIT", 1]]
  ↳ /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
  Rendering /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
  MenuItem Load (0.6ms)  SELECT  "menu_items".* FROM "menu_items" WHERE "menu_items"."id" = ? LIMIT ?  [["id", 2], ["LIMIT", 1]]
  ↳ /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
  MenuItem Load (0.2ms)  SELECT "menu_items".* FROM "menu_items" ORDER BY menu_items.id desc
  ↳ /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
  Rendered /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_filtering_select.html.haml (10.1ms)
  Rendered /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_field.html.haml (1.3ms)
  Rendered /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (1.4ms)
  ActiveStorage::Attachment Load (0.2ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = ? AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ?  [["record_id", 7], ["record_type", "Product"], ["name", "images"]]
  ↳ /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
  ActiveStorage::Blob Load (0.1ms)  SELECT  "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 4], ["LIMIT", 1]]
  ↳ /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
  Rendered /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (11.8ms)
  Rendered /Users/h.bento/.rvm/gems/ruby-2.5.3@hl/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (46.4ms)
Completed 500 Internal Server Error in 69ms (ActiveRecord: 1.3ms)


undefined method `' for #<Product:0x00007fa14b7ad228> excluded from capture: DSN not set

ActionView::Template::Error (undefined method `' for #<Product:0x00007fa14b7ad228>):
     6:         %i.icon-white.icon-trash
     7:         = I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase} ##{i + 1}"
     8:
     9:     = form.check_box(field.delete_method, {multiple:true, style: 'display:none;'}, attachment.delete_key, nil)
    10:
    11: = form.file_field(field.name, field.html_attributes.reverse_merge({ data: { :"multiple-fileupload" => true }, multiple: true }))
    12:

activemodel (5.2.2) lib/active_model/attribute_methods.rb:430:in `method_missing'
rails_admin (1.4.2) lib/rails_admin/adapters/active_record/abstract_object.rb:27:in `public_send'
rails_admin (1.4.2) lib/rails_admin/adapters/active_record/abstract_object.rb:27:in `method_missing'
actionview (5.2.2) lib/action_view/helpers/tags/base.rb:42:in `value'
actionview (5.2.2) lib/action_view/helpers/tags/checkable.rb:12:in `input_checked?'
actionview (5.2.2) lib/action_view/helpers/tags/check_box.rb:21:in `render'
actionview (5.2.2) lib/action_view/helpers/form_helper.rb:1295:in `check_box'
actionview (5.2.2) lib/action_view/helpers/form_helper.rb:2087:in `check_box'
rails_admin (1.4.2) app/views/rails_admin/main/_form_multiple_file_upload.html.haml:9:in `block in ___sers_h_bento__rvm_gems_ruby_______hl_gems_rails_admin_______app_views_rails_admin_main__form_multiple_file_upload_html_haml___1599974643987141842_70165425602680'

@knt930
Copy link

knt930 commented Jun 10, 2019

I have the same problem.
While I refer to the carrierwave document, I added "images:json" column to Shop model.

And I setted up like this

class Shop < ApplicationRecord
  mount_uploader :images, ImageUploader
  attr_accessor :delete_images
  after_validation do
    uploaders = images.delete_if do |uploader|
      if Array(delete_images).include?(uploader.file.identifier)
        uploader.remove!
        true
      end
    end
    write_attribute(:images, uploaders.map { |uploader| uploader.file.identifier })
  end

  def images=(files)
    appended = files.map do |file|
      uploader = _mounter(:images).blank_uploader
      uploader.cache! file
      uploader
    end
    super(images + appended)
  end
end

After that, when I try to create a new Shop instance with rails_admin view, the following error is displayed.

Completed 500 Internal Server Error in 27ms (ActiveRecord: 0.6ms)


  
ActionView::Template::Error (undefined method `identifier' for nil:NilClass):
     6:         %i.icon-white.icon-trash
     7:         = I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase} ##{i + 1}"
     8: 
     9:     = form.check_box(field.delete_method, {multiple:true, style: 'display:none;'}, attachment.delete_key, nil)
    10: 
    11: = form.file_field(field.name, field.html_attributes.reverse_merge({ data: { :"multiple-fileupload" => true }, multiple: true }))
    12: 

@knt930
Copy link

knt930 commented Jun 11, 2019

It seems that "identifier" method can not be used in CarrierWave::Storage::Fog::File

It should be changed "identifier" to "filename" method. This can return the same value we want.

@mshibuya mshibuya added this to the 2.0.0 milestone Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants