Goal => Have a multiple file uploader working.
I am getting the following error when I try to mount the uploader.
[email protected] (Message)> mount_uploaders :attachments, AttachmentUploader
NoMethodError: undefined method `mount_uploaders' for #<Class:0x007fc17b4cc658>
from /Users/mm/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.1.7/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
If I remove the s on the end of uploaders I get:
[email protected] (Message)> mount_uploader :attachments, AttachmentUploader
=> :serializable_hash
Based on this I thought I should confirm the class is correct. This is what I can:
[email protected] (Message)> AttachmentUploader
=> AttachmentUploader < CarrierWave::Uploader::Base
My model is:
class Message < ActiveRecord::Base
belongs_to :user
belongs_to :conversation
delegate :list, to: :conversation, allow_nil: true
mount_uploaders :attachments, AttachmentUploader
end
My AttachmentUploader class is:
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
end
In the database my messages table is:
create_table "messages", force: true do |t|
t.integer "user_id"
t.integer "conversation_id"
t.datetime "created_at"
t.datetime "updated_at"
t.text "payload"
t.hstore "headers", default: {}, null: false
t.hstore "to", default: [], array: true
t.hstore "from", default: {}, null: false
t.string "subject"
t.hstore "cc", default: [], array: true
t.text "body"
t.text "raw_body"
t.text "raw_html"
t.json "attachments"
end
Based this I can't see why it isn't loading as I have followed the instructions in the README as per here - https://github.com/carrierwaveuploader/carrierwave#multiple-file-uploads
Here is a full stacktrace if I launch rspec:
➜ GroupMailer git:(add_attachments) ✗ rspec
Coverage report generated for RSpec to /Users/matthewbarram/projects/GroupMailer/coverage. 48 / 100 LOC (48.0%) covered.
/Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.1.7/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `mount_uploaders' for #<Class:0x007f9269adfae0> (NoMethodError)
from /Users/matthewbarram/projects/GroupMailer/app/models/message.rb:5:in `<class:Message>'
from /Users/matthewbarram/projects/GroupMailer/app/models/message.rb:1:in `<top (required)>'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:348:in `require_or_load'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:480:in `load_missing_constant'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:180:in `const_missing'
from /Users/matthewbarram/projects/GroupMailer/spec/models/message_spec.rb:3:in `<top (required)>'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/matthewbarram/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /Users/matthewbarram/.rbenv/versions/2.1.3/bin/rspec:23:in `load'
from /Users/matthewbarram/.rbenv/versions/2.1.3/bin/rspec:23:in `<main>'
Any help would be amazing! I have been stuck on this for a few hours. :-)
Thanks!
It turns out the issue was the method did not exist in the gem.
I re-installed the gem without success. Then I referenced the github master branch manually, re-installed and it worked.
I think you have to require the extension manually, as suggested here. Can you try that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With