Rails Admin - undefined method `' for using Carrierwave multiple upload
I can't edit some records in Rails Admin after do a multiple files upload using Carrierwave.
I guess that did the correct config, when I upload the files everything goes well, but if I try edit after save the record that error happens:
.log:
14:33:56 web.1 | Started POST "/admin/__better_errors/563c2613b62e459f/variables" for 127.0.0.1 at 2018-11-21 14:33:56 -0200
14:33:56 web.1 | Tag Load (0.6ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 LIMIT $2 [["project_id", 75],["LIMIT", 11]]
14:33:56 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:50 web.1 | Started GET "/admin/project/75/edit" for 127.0.0.1 at 2018-11-21 14:34:50 -0200
14:34:50 web.1 | Processing by RailsAdmin::MainController#edit as HTML
14:34:50 web.1 | Parameters: {"model_name"=>"project", "id"=>"75"}
14:34:50 web.1 | Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
14:34:50 web.1 | ↳ config/initializers/rails_admin.rb:9
14:34:50 web.1 | Project Load (2.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 ORDER BY "projects"."id" ASC LIMIT $2 [["id", 75], ["LIMIT", 1]]
14:34:50 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendering /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_field.html.haml (3.8ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (31.4ms)
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 [["project_id", 75]]
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | (0.4ms) SELECT COUNT(*) FROM "tags"
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" ORDER BY tags.id desc
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (22.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_file_upload.html.haml (13.9ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (45.1ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (623.9ms)
14:34:51 web.1 | Completed 500 Internal Server Error in 800ms (ActiveRecord: 3.9ms)
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 | NoMethodError - undefined method `' for #<Project:0x00007fb7cfa36900>:
14:34:51 web.1 |
rails_admin.rb:
config.model Project do
edit do
field :title
field :headline
field :images, :multiple_carrierwave
end
end
ProjectImageUploader.rb
class ProjectImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
process optimize: [{ quality: 85 }]
storage :file
version :normal do
process :efficient_conversion => [640, 960]
end
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
private
def efficient_conversion(width, height)
manipulate! do |img|
img.combine_options do |c|
c.fuzz "3%"
c.trim
c.resize "#{width}x#{height}>"
c.resize "#{width}x#{height}<"
end
img
end
end
end
Project model:
mount_uploaders :images, ProjectImageUploader
ruby-on-rails ruby carrierwave rails-admin
add a comment |
I can't edit some records in Rails Admin after do a multiple files upload using Carrierwave.
I guess that did the correct config, when I upload the files everything goes well, but if I try edit after save the record that error happens:
.log:
14:33:56 web.1 | Started POST "/admin/__better_errors/563c2613b62e459f/variables" for 127.0.0.1 at 2018-11-21 14:33:56 -0200
14:33:56 web.1 | Tag Load (0.6ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 LIMIT $2 [["project_id", 75],["LIMIT", 11]]
14:33:56 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:50 web.1 | Started GET "/admin/project/75/edit" for 127.0.0.1 at 2018-11-21 14:34:50 -0200
14:34:50 web.1 | Processing by RailsAdmin::MainController#edit as HTML
14:34:50 web.1 | Parameters: {"model_name"=>"project", "id"=>"75"}
14:34:50 web.1 | Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
14:34:50 web.1 | ↳ config/initializers/rails_admin.rb:9
14:34:50 web.1 | Project Load (2.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 ORDER BY "projects"."id" ASC LIMIT $2 [["id", 75], ["LIMIT", 1]]
14:34:50 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendering /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_field.html.haml (3.8ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (31.4ms)
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 [["project_id", 75]]
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | (0.4ms) SELECT COUNT(*) FROM "tags"
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" ORDER BY tags.id desc
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (22.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_file_upload.html.haml (13.9ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (45.1ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (623.9ms)
14:34:51 web.1 | Completed 500 Internal Server Error in 800ms (ActiveRecord: 3.9ms)
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 | NoMethodError - undefined method `' for #<Project:0x00007fb7cfa36900>:
14:34:51 web.1 |
rails_admin.rb:
config.model Project do
edit do
field :title
field :headline
field :images, :multiple_carrierwave
end
end
ProjectImageUploader.rb
class ProjectImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
process optimize: [{ quality: 85 }]
storage :file
version :normal do
process :efficient_conversion => [640, 960]
end
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
private
def efficient_conversion(width, height)
manipulate! do |img|
img.combine_options do |c|
c.fuzz "3%"
c.trim
c.resize "#{width}x#{height}>"
c.resize "#{width}x#{height}<"
end
img
end
end
end
Project model:
mount_uploaders :images, ProjectImageUploader
ruby-on-rails ruby carrierwave rails-admin
Could you edit your question to include this view please:rails_admin/main/edit.html.haml?
– SRack
Jan 24 at 17:03
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55
add a comment |
I can't edit some records in Rails Admin after do a multiple files upload using Carrierwave.
I guess that did the correct config, when I upload the files everything goes well, but if I try edit after save the record that error happens:
.log:
14:33:56 web.1 | Started POST "/admin/__better_errors/563c2613b62e459f/variables" for 127.0.0.1 at 2018-11-21 14:33:56 -0200
14:33:56 web.1 | Tag Load (0.6ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 LIMIT $2 [["project_id", 75],["LIMIT", 11]]
14:33:56 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:50 web.1 | Started GET "/admin/project/75/edit" for 127.0.0.1 at 2018-11-21 14:34:50 -0200
14:34:50 web.1 | Processing by RailsAdmin::MainController#edit as HTML
14:34:50 web.1 | Parameters: {"model_name"=>"project", "id"=>"75"}
14:34:50 web.1 | Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
14:34:50 web.1 | ↳ config/initializers/rails_admin.rb:9
14:34:50 web.1 | Project Load (2.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 ORDER BY "projects"."id" ASC LIMIT $2 [["id", 75], ["LIMIT", 1]]
14:34:50 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendering /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_field.html.haml (3.8ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (31.4ms)
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 [["project_id", 75]]
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | (0.4ms) SELECT COUNT(*) FROM "tags"
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" ORDER BY tags.id desc
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (22.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_file_upload.html.haml (13.9ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (45.1ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (623.9ms)
14:34:51 web.1 | Completed 500 Internal Server Error in 800ms (ActiveRecord: 3.9ms)
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 | NoMethodError - undefined method `' for #<Project:0x00007fb7cfa36900>:
14:34:51 web.1 |
rails_admin.rb:
config.model Project do
edit do
field :title
field :headline
field :images, :multiple_carrierwave
end
end
ProjectImageUploader.rb
class ProjectImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
process optimize: [{ quality: 85 }]
storage :file
version :normal do
process :efficient_conversion => [640, 960]
end
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
private
def efficient_conversion(width, height)
manipulate! do |img|
img.combine_options do |c|
c.fuzz "3%"
c.trim
c.resize "#{width}x#{height}>"
c.resize "#{width}x#{height}<"
end
img
end
end
end
Project model:
mount_uploaders :images, ProjectImageUploader
ruby-on-rails ruby carrierwave rails-admin
I can't edit some records in Rails Admin after do a multiple files upload using Carrierwave.
I guess that did the correct config, when I upload the files everything goes well, but if I try edit after save the record that error happens:
.log:
14:33:56 web.1 | Started POST "/admin/__better_errors/563c2613b62e459f/variables" for 127.0.0.1 at 2018-11-21 14:33:56 -0200
14:33:56 web.1 | Tag Load (0.6ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 LIMIT $2 [["project_id", 75],["LIMIT", 11]]
14:33:56 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:50 web.1 | Started GET "/admin/project/75/edit" for 127.0.0.1 at 2018-11-21 14:34:50 -0200
14:34:50 web.1 | Processing by RailsAdmin::MainController#edit as HTML
14:34:50 web.1 | Parameters: {"model_name"=>"project", "id"=>"75"}
14:34:50 web.1 | Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
14:34:50 web.1 | ↳ config/initializers/rails_admin.rb:9
14:34:50 web.1 | Project Load (2.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 ORDER BY "projects"."id" ASC LIMIT $2 [["id", 75], ["LIMIT", 1]]
14:34:50 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendering /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_field.html.haml (3.8ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (31.4ms)
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" INNER JOIN "projects_tags" ON "tags"."id" = "projects_tags"."tag_id" WHERE "projects_tags"."project_id" = $1 [["project_id", 75]]
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | (0.4ms) SELECT COUNT(*) FROM "tags"
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Tag Load (0.5ms) SELECT "tags".* FROM "tags" ORDER BY tags.id desc
14:34:51 web.1 | ↳ /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (22.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_text.html.haml (0.4ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_file_upload.html.haml (13.9ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/_form_multiple_file_upload.html.haml (45.1ms)
14:34:51 web.1 | Rendered /Users/Atua/.rvm/gems/ruby-2.5.1@atua/gems/rails_admin-1.4.2/app/views/rails_admin/main/edit.html.haml within layouts/rails_admin/application (623.9ms)
14:34:51 web.1 | Completed 500 Internal Server Error in 800ms (ActiveRecord: 3.9ms)
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 |
14:34:51 web.1 | NoMethodError - undefined method `' for #<Project:0x00007fb7cfa36900>:
14:34:51 web.1 |
rails_admin.rb:
config.model Project do
edit do
field :title
field :headline
field :images, :multiple_carrierwave
end
end
ProjectImageUploader.rb
class ProjectImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
process optimize: [{ quality: 85 }]
storage :file
version :normal do
process :efficient_conversion => [640, 960]
end
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
private
def efficient_conversion(width, height)
manipulate! do |img|
img.combine_options do |c|
c.fuzz "3%"
c.trim
c.resize "#{width}x#{height}>"
c.resize "#{width}x#{height}<"
end
img
end
end
end
Project model:
mount_uploaders :images, ProjectImageUploader
ruby-on-rails ruby carrierwave rails-admin
ruby-on-rails ruby carrierwave rails-admin
asked Nov 21 '18 at 16:47
Felipe MarconFelipe Marcon
9610
9610
Could you edit your question to include this view please:rails_admin/main/edit.html.haml?
– SRack
Jan 24 at 17:03
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55
add a comment |
Could you edit your question to include this view please:rails_admin/main/edit.html.haml?
– SRack
Jan 24 at 17:03
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55
Could you edit your question to include this view please:
rails_admin/main/edit.html.haml?– SRack
Jan 24 at 17:03
Could you edit your question to include this view please:
rails_admin/main/edit.html.haml?– SRack
Jan 24 at 17:03
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55
add a comment |
1 Answer
1
active
oldest
votes
I had same problem and add this methods into model helped me:
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
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416886%2frails-admin-undefined-method-for-using-carrierwave-multiple-upload%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I had same problem and add this methods into model helped me:
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
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
add a comment |
I had same problem and add this methods into model helped me:
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
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
add a comment |
I had same problem and add this methods into model helped me:
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
I had same problem and add this methods into model helped me:
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
answered Feb 11 at 18:52
user1956092user1956092
364
364
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
add a comment |
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
Thanks. This worked! :D
– Felipe Marcon
Feb 25 at 17:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416886%2frails-admin-undefined-method-for-using-carrierwave-multiple-upload%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you edit your question to include this view please:
rails_admin/main/edit.html.haml?– SRack
Jan 24 at 17:03
@SRack I don't have this file on my project :/ RailsAdmin and CarrierWave handle this.
– Felipe Marcon
Feb 4 at 15:55