When running feature Rspecs, I receive the following error (full trace at the bottom of this message)
Puma output
Rack app error handling request { GET /rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZSM0IxTkRGRFRWQlFaVXRNYVUxaVpuQjZXVmw1UTNBMUx6RXhNR1V3TVRka01UWTVNalZrWXpkak5UQTNNamhqT1dNeE5UUmhOREl3TURjNVlXRTJaVFZtWTJNME16VmtZak5sTm1VNU4ySXhNemd3WldObFl6Z0dPZ1pGVkRvUVpHbHpjRzl6YVhScGIyNUpJajFwYm14cGJtVTdJR1pwYkdWdVlXMWxQU0pwYldGblpTNXdibWNpT3lCbWFXeGxibUZ0WlNvOVZWUkdMVGduSjJsdFlXZGxMbkJ1WndZN0JsUTZFV052Ym5SbGJuUmZkSGx3WlVraURtbHRZV2RsTDNCdVp3WTdCbFE9IiwiZXhwIjoiMjAxOS0wMS0yNVQxMToxNjoyOS40NDBaIiwicHVyIjoiYmxvYl9rZXkifX0=--db9451afdc95b292aa6a77c40e00ab0ceb687766/image.png }
#<Errno::ENOENT: No such file or directory # rb_file_s_mtime - /path/to/rails/app/tmp/storage/va/ri/variants/Gpu41CMPPeKLiMbfpzYYyCp5/110e017d16925dc7c50728c9c154a420079aa6e5fcc435db3e6e97b1380ecec8>
(followed by the full trace at the end of this message)
Rspec outpout
Failure/Error: last_modified = ::File.mtime(path).httpdate
Errno::ENOENT:
No such file or directory # rb_file_s_mtime - /path/to/rails/app/tmp/storage/va/ri/variants/Gpu41CMPPeKLiMbfpzYYyCp5/110e017d16925dc7c50728c9c154a420079aa6e5fcc435db3e6e97b1380ecec8
(followed by the full trace at the end of this message)
Context
product.image is an ActiveStorage attachment. During the test the "products/_form" partial is rendered and is displaying the attachment file (namely a png image) with the following code: = image_tag url_for(product.image.variant(resize: "120x120")). If I comment out this line, the error does not occur anymore.
The test itself succeed every times, the error seems to be triggered after the test. I verified all my after blocks, it seems to happen after all my after blocks.
The trace indicates that ActiveStorage::DiskController.serve_file triggers the errors. Is it that ActiveStorage app is not shutting down gracefully ?
I'm using active_storage.service = :test configuration, but :file gives the same errors.
Image broken
While a test fail, I can see in the "remote controlled" browser that the image is not display and there is a broken image icon instead.
Running the tests
There is a group of 4 featured tests that are going through the render of the "products/_form" partial. When I run the 4 tests in a random order the error occurs randomly. Sometime I can see the error 2 times, sometimes 3 times.
when I run the tests individually the error does never appear.
How I attach the image
This is the helper I use to attach the file to the model before going through the test :
path = Rails.root.join 'spec', 'support', 'fixtures', 'img1.png'
raise 'Image does not exist' unless File.exist? path
product.image.attach io: File.open(path), filename: 'image.png'
I also tried to use this helper :
path = Rails.root.join 'spec', 'support', 'fixtures', 'img1.png'
raise 'Image does not exist' unless File.exist? path
blob = ActiveStorage::Blob.create_after_upload! io: path.open, \
filename: 'img1.png', content_type: 'image/png'
product.images.attach blob
And this helper :
path = Rails.root.join 'spec', 'support', 'fixtures', 'img1.png'
raise 'Image does not exist' unless File.exist? path
byte_size = path.size
checksum = Digest::MD5.file(path).base64digest
blob = ActiveStorage::Blob.create_before_direct_upload!(filename: 'img1.png', \
byte_size: byte_size, checksum: checksum, content_type: 'image/png').tap do |blob|
ActiveStorage::Blob.service.upload(blob.key, path.open)
end
product.images.attach blob
System configuration
Rails version: 5.2.2
Ruby version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
Rbenv version: rbenv 1.1.1-39-g59785f6
Rspec related versions: rspec 3.8.0 - capybara 3.12.0 - selenium-webdriver 3.141.0
Full trace
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/file.rb:63:in `mtime'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/file.rb:63:in `serving'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activestorage-5.2.2/app/controllers/active_storage/disk_controller.rb:42:in `serve_file'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activestorage-5.2.2/app/controllers/active_storage/disk_controller.rb:12:in `show'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/abstract_controller/base.rb:194:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/rendering.rb:30:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:132:in `run_callbacks'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/abstract_controller/callbacks.rb:41:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/rescue.rb:22:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:168:in `block in instrument'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:168:in `instrument'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/abstract_controller/base.rb:134:in `process'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionview-5.2.2/lib/action_view/rendering.rb:32:in `process'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal.rb:191:in `dispatch'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_controller/metal.rb:252:in `dispatch'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:34:in `serve'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/journey/router.rb:52:in `block in serve'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/journey/router.rb:35:in `each'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/journey/router.rb:35:in `serve'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:840:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/etag.rb:25:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/conditional_get.rb:25:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in `context'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/cookies.rb:670:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:98:in `run_callbacks'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:38:in `call_app'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `block in call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:28:in `tagged'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `tagged'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/static.rb:127:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:524:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:68:in `block in call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `each'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/capybara-3.12.0/lib/capybara/server/middleware.rb:48:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# Capybara::CapybaraError:
# Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true
# /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/capybara-3.12.0/lib/capybara/session.rb:147:in `raise_server_error!'
Update
(Sorry for being silent, I had an emergency to attend to)
Here is an interesting information. I inserted after this line, this code: puts "SERVING #{path} - Exist ? #{File.exist? path}"
And here is the output (observe the files names and the boolean value at the end of each line):
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Me/GK/MeGKkqgbb7Sg4RbPoCYWR6pZ - Exist ? true
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/sG/3v/sG3vd2viGWmaf69pNXSChZPa - Exist ? true
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/fy/2C/fy2C8PpaR96YgCzwt5WVBLrQ - Exist ? true
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/sG/3v/sG3vd2viGWmaf69pNXSChZPa - Exist ? true
. (green dot)
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Me/GK/MeGKkqgbb7Sg4RbPoCYWR6pZ - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/sG/3v/sG3vd2viGWmaf69pNXSChZPa - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Me/GK/MeGKkqgbb7Sg4RbPoCYWR6pZ - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/fy/2C/fy2C8PpaR96YgCzwt5WVBLrQ - Exist ? false
F (red F)
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Me/GK/MeGKkqgbb7Sg4RbPoCYWR6pZ - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/sG/3v/sG3vd2viGWmaf69pNXSChZPa - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Me/GK/MeGKkqgbb7Sg4RbPoCYWR6pZ - Exist ? false
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/fy/2C/fy2C8PpaR96YgCzwt5WVBLrQ - Exist ? false
F (red F)
SERVING /tmp/active_storage_tests20190129-10797-1rebdf7/Tx/DL/TxDLPEk3ykf8ETkURY5YZPgY - Exist ? true
As we can see the files path are the same, even between tests. Tough the database is cleaned between each tests. So there is "somewhere" where the file checksum is kept, for activestorage to reuse the same blob record. As a result it reuse the same file path and that's the reason why I have a FileNotFound error.
Any idea ? Please note that, additionally to DatabaseCleaner, I have an after block defined like this :
config.after(:each) do
ActiveStorage::Current.reset
ActiveStorage::Attachment.all.each(&:delete)
ActiveStorage::Blob.all.each(&:delete)
end
I suspect a bug
Filled a PR with an application to reproduce https://github.com/rails/rails/issues/34989
Waiting for them response
The fact that the test passes just means that the test does not depend on that image being found. A broken image link will not generally cause a test to fail and it is in fact often the case that test writers do not even bother to supply mock images because it is (perceived to be) too much work and not relevant to the thing being tested.
See folks, this is why we ask for an example. Now that the OP has posted an example, we can see that his problem is browser caching, and will be solved by replacing
product.images.attach io: File.open(path), filename: 'image.png'
with
product.images.attach io: File.open(path), filename: "image-#{Time.now.strftime("%s%L")}.png"
in the helper that does the attachment. I would not have solved this without having the example.
Explanation
ActiveStorage handles saving and serving files. OP was saving and serving images with it, which is definitely what it was intended for. In order to allow for different services to serve files in different ways, ActiveStorage separates the published URL from the actual image serving URL.
The published URL is almost a permalink: it is an encoded version of the database key for the attachment. ActiveStorage processes a request for the URL by looking up where the file is stored and sending a 302 temporary redirect to the URL that can be used to access the file, called a "service URL". When using AWS S3 to store files, the service URL can be a signed URL that expires quickly but nevertheless connects the browser directly to S3 rather than having to go through the web server as intermediary.
By default, the service URL is good for 5 minutes, and ActiveRecord explicitly sets
Cache-Control: max-age=300, private
on the 302 redirect. The browser caches this redirect response and for the next 5 minutes the browser will not even attempt to use or verify the published URL, it will immediately replace the public URL with the cached service URL.
Unfortunately, while the public URL is predictably recreated, the service URL is randomly generated, so when the browser does its automatic redirection, the previously valid service URL no longer works. The solution (or workaround, depending on your point of view) is to distinguish the public URLs by including a timestamp in the filename, so that tests will not reuse public URLs.
Sidenote
By the way, you should not be using url_for with image_tag. Change your ERB from
= image_tag url_for(product.image.variant(resize: "120x120"))
to
= image_tag(product.image.variant(resize: "120x120"))
Rails is smart enough to handle either case, but the latter way is the recommended way.
Something is likely off with how you're setting up the image that you're testing against. You might want to update that to how the Rails team handles it in their own tests:
module ActiveStorageHelpers
# ported from https://github.com/rails/rails/blob/5-2-stable/activestorage/test/test_helper.rb#L57
def create_file_blob(filename: "image.jpg", content_type: "image/jpeg", metadata: nil)
ActiveStorage::Blob.create_after_upload! io: file_fixture(filename).open, filename: filename, content_type: content_type, metadata: metadata
end
end
RSpec.configure do |config|
config.include ActiveStorageHelpers
end
Then place a tiny image file in spec/fixtures/file/images.jpg (that's where the file_fixture method will look for it).
With that in place, you can setup the image on your model in your feature test with something like:
instance_of_model.images.attach(create_file_blob)
I'm not sure what you mean with the exception happens after the test?
Test should be usually atomic and independent, so all resources you create should be removed immediately after your test finished.
Also tests are running in random order, so tests which rely on each other will fail sometimes - and sometimes not, depending on the run order.
Can you share the output or tests which fail?
I'm having issue with paperclip and heroku and really need help.I've lost the past 2 days getting stuck on this and none of the link i could found helped :
https://github.com/igor-alexandrov/paperclip-aws"
"http://www.codeitive.com/0QHVXqkUVV/heroku-paperclip-s3-error-%3E- awss3errorssignaturedoesnotmatch.html"
"https://devcenter.heroku.com/articles/paperclip-s3#international-users-additional-configuration"
"http://dchua.com/2011/12/27/how-to-get-paperclip-and-aws-s3-singapore-and-european-buckets-working/"
"http://www.kahfei.com/?p=389"
"http://www.conandalton.net/2011/02/paperclip-s3-and-european-buckets.html"
"http://stackoverflow.com/questions/20424724/ruby-on-rails-paperclip-amazon-aws-s3-heroku"
"http://stackoverflow.com/questions/7257745/rails-3-amazon-s3-paperclip-eu-problem"
In the beginning i wanted to use an european S3 location but since it seems to make everything more complicated i've decided to switch back to the default US location.
I've setup my VARS as follow on terminal :
$ heroku config:set S3_BUCKET_NAME=your_bucket_name
$ heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
$ heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key
Then inside my config/environment/production.rb :
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
When going to my website and trying to upload a picture my heroku log is as follow :
Running `bundle exec rake db:seed` attached to terminal... up, run.8070
rake aborted!
AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:375:in `return_or_raise'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:476:in `client_request'
(eval):3:in `put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:1765:in `write_with_put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:611:in `write'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:360:in `block in flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/attachment.rb:238:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-meta-1.2.0/lib/paperclip-meta/attachment.rb:16:in `save_with_meta_data'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/has_attached_file.rb:91:in `block in add_active_record_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `block in halting_and_conditional'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:142:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/validations.rb:43:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `block in save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:51:in `create!'
/app/db/seeds.rb:9:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
Obviously i've double checked my heroku configs and trying to input both key and bucket again => no change.
At this point i've tried so many stuff that i'm at lost.
Setting heroku stuff inside my model after attached_files
Setting heroku YAML file in addition to heroku config var
Tried both european and us standard buckets
If anyone has any idea.. All the research i did on that error didn't help one bit : AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
Ok just go it working so for the next person having that issue :
-Don't follow the heroku paperclip tutorial
-Create a aws.yml file in your config folder with inside :
development:
access_key_id: "xxxxxinquote"
secret_access_key: "yyyyyinquote"
test:
access_key_id: abc...
secret_access_key: abc...
production:
access_key_id: "xxx"
secret_access_key: "yyyy"
-Inside all your models with file upload put :
has_attached_file :image,
:styles => { :medium => "460x>", :thumb => "100x100>",:vnice=> "400x" },
:storage => :s3,
:bucket => 'hohohohoho',
:s3_credentials => "#{Rails.root}/config/aws.yml",
:path => "resources/:id/:style/:basename.:extension
Then inside your production or/and dev.rb
config.paperclip_defaults = {
:storage => :s3,
:bucket => ENV['S3_BUCKET_NAME'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
Note : :bucket is OUTSIDE the s3 credentials unlike what is said in the tutorial.
Hope it can help someone
I am using Rails 3.2.14, thinking-sphinx 3.1.1 and Sphinx 2.2.4-id64-release (r4806)
I have two modals below:-
Album.rb
has_and_belongs_to_many :genres
Genre.rb
has_and_belongs_to_many :albums
So the associated table is albums_genres
I want to search albums using the genre_id
Example: When I pass a genre_id then it should return all the albums associated to that genre_id on the basis of third table albums_genres
I have tried like that
ThinkingSphinx::Index.define :album, :with => :active_record do
#other indexes
has genres.id, :as => :genre_ids, :source => :query
end
But when i run the rake task as rake ts:index i am getting the error as:-
rake aborted!
undefined method `join_table' for #<ActiveRecord::Reflection::AssociationReflection:0x000000079224d8>
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:15:in `quoted_foreign_key'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:28:in `to_sql'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/property_query.rb:76:in `queries'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:5:in `to_s'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/property_query.rb:15:in `to_s'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:45:in `query'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:38:in `multi_declaration'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:23:in `declaration'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:96:in `block in append_presenter_to_attribute_array'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `each'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `append_presenter_to_attribute_array'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:132:in `prepare_for_render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:65:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `block in render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `collect'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:53:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `block in render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `collect'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:90:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:24:in `index'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in `eval'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in `<main>'
It looks like this is a bug with Rails 3.2, :source => :query and HABTM joins (which is sadly not surprising - getting the code to work even with Rails 4.0 was painful and fragile).
I'm afraid your options are either upgrade to Rails 4 or not use the :source => :query option (and I know that means you lose some nice speed gains for indexing).
Odds of me getting a patch sorted in the near future is small (but others are welcome to give it a shot, if they wish).
I'm using the twitter gem along with amniauth to fetch a user's tweets and display them on my homepage. But when I try to grab tweets from the command line I'm getting a 'bad authentication data' error.
Gemfile:
gem 'omniauth'
gem 'omniauth-twitter'
gem 'twitter'
Twitter.rb in config/initializers:
Twitter.configure do |config|
config.consumer_key = 'key'
config.consumer_secret = 'secret'
config.oauth_token = 'token'
config.oauth_token_secret = 'secret'
end
omniauth.rb in config/initializers:
require 'omniauth-twitter'
config.omniauth :twitter, 'key', 'secret'
I've double checked my key and passwords, but I can't get it to run. I am using Spree. Here's the error:
irb(main):001:0> require 'twitter'
=> true
irb(main):002:0> Twitter.user_timeline(213747670)
Twitter::Error::BadRequest: Bad Authentication data
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/response/raise_error.rb:21:in `on_complete'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:9:in `block in call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:63:in `on_complete'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/request/url_encoded.rb:14:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/request/multipart.rb:13:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/request/multipart_with_file.rb:14:in `call'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/connection.rb:247:in `run_request'
from /usr/local/lib64/ruby/gems/1.9.1/gems/faraday-0.8.7/lib/faraday/connection.rb:100:in `get'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/client.rb:81:in `request'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/client.rb:64:in `get'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/utils.rb:51:in `objects_from_response'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/utils.rb:42:in `objects_from_response_with_user'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter/api/timelines.rb:53:in `user_timeline'
from /usr/local/lib64/ruby/gems/1.9.1/gems/twitter-4.6.2/lib/twitter.rb:52:in `method_missing'
from (irb):2
Thanks for your help.
To fetch and display user's tweets its better to go with twitter gem.
Refer the following links for step-by-step instructions
http://shouweick.blogspot.in/2011/11/rails-3-and-twitter-api-by-shouweick.html?showComment=1381925399790#c6571680143535387130
https://gist.github.com/fnichol/867550
Let's say I had the email address like putin-crab#президент.рф
How to validate that address in rails 3.1?
My Model(i use Mongoid):
#encoding: utf-8
class User
include Mongoid::Document
field :email, :type => String
validates :email, :presence => true, :format => { :with => RFC822::EMAIL }
end
For validations reqexp i use gem https://github.com/dim/rfc-822
in rails console (normal email):
ruby-1.9.2-p290 :001 > usr = User.new( :email => "pretty#gmail.com" )
=> #<User _id: 4ec627cf4934db7e4d000001, _type: nil, email: "pretty#gmail.com">
ruby-1.9.2-p290 :002 > usr.valid?
=> true
in rails console (fu##ing email):
ruby-1.9.2-p290 :003 > usr = User.new( :email => "putin-crab#президент.рф" )
=> #<User _id: 4ec627f44934db7e4d000002, _type: nil, email: "putin-crab#президент.рф">
ruby-1.9.2-p290 :004 > usr.valid?
Encoding::CompatibilityError: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `=~'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `!~'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `validate_each'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:153:in `block in validate'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:150:in `each'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:150:in `validate'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:302:in `_callback_before_13'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:404:in `_run_validate_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:42:in `block in run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `call'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:41:in `run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations.rb:212:in `run_validations!'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:390:in `_run_validation_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:42:in `block in run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `call'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:41:in `run_callbacks'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/activemodel-3.1.1/lib/active_model/validations.rb:179:in `valid?'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/mongoid-2.3.3/lib/mongoid/validations.rb:70:in `valid?'
from (irb):4
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/username/.rvm/gems/ruby-1.9.2-p290#rail31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
Emails cannot be recognized by Regexps because they are not a Regular language.
There are several good ways to validate an email address in Ruby (and Rails), each with various trade-offs:
If you only want to validate that it's the correct format, use a dedicated specific parser like the one from TMail, and see if the input is accepted (parsed successfully) (NOT A REGEXP). For example https://github.com/codyrobbins/active-model-email-validator
Once the email is known to have a correct format you can go a step further, and "talk to the internet" by doing DNS queries to see that the email's domain resolves and has mails servers (MX records) specified like https://github.com/Empact/validates_email_veracity_of although this might be too much.