'RailsTutorial 13 --- Image doesn't show on the web page after uploading it through AWS S3
I am a newbie and just started to learn coding with RailsTutorial. I use AWS C9 Ubuntu as is instructed.
At the end of chapter 13, there is an instruction for AWS S3 and I'm supposed to be able to upload image from my own app using S3 bucket. Yet, after uploading image, all I can see is the blank image icon whose link reads like,
"my-app-name.herokuapp.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6e6a44c62e3827d7e210d52630982c8828a73e4b/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQXZRQmFRTDBBUT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--1644d67e3b1971d7c6c2be43c754947f51bc334d/img_6627-copy.jpg"
The uploaded image fails to show on the web page
The heroku log reads as shown below and there is an error saying "ArgumentError (wrong number of arguments (given 1, expected 0)):" I changed the image name to be all lowercase since I saw someone pointed it out on the net, yet without avail.
$ heroku logs --tail
`2022-05-13T01:08:16.860200+00:00 app[web.1]: I, [2022-05-13T01:08:16.860119 #20] INFO -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] Started GET "/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6e6a44c62e3827d7e210d52630982c8828a73e4b/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQXZRQmFRTDBBUT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--1644d67e3b1971d7c6c2be43c754947f51bc334d/img_6627-copy.jpg" for 218.110.232.237 at 2022-05-13 01:08:16 +0000
2022-05-13T01:08:16.861399+00:00 app[web.1]: I, [2022-05-13T01:08:16.861328 #20] INFO -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] Processing by ActiveStorage::RepresentationsController#show as JPEG
2022-05-13T01:08:16.861455+00:00 app[web.1]: I, [2022-05-13T01:08:16.861423 #20] INFO -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] Parameters: {"signed_blob_id"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6e6a44c62e3827d7e210d52630982c8828a73e4b", "variation_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQXZRQmFRTDBBUT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--1644d67e3b1971d7c6c2be43c754947f51bc334d", "filename"=>"img_6627-copy"}
2022-05-13T01:08:16.895691+00:00 app[web.1]: D, [2022-05-13T01:08:16.895633 #20] DEBUG -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] ActiveStorage::Blob Load (1.0ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 4], ["LIMIT", 1]]
2022-05-13T01:08:17.505057+00:00 app[web.1]: D, [2022-05-13T01:08:17.504803 #20] DEBUG -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] S3 Storage (608.5ms) Checked if file exists at key: variants/d6gum4prxe21jwhticu2jln53k6a/091909a1e0588062e474bcd888ce6b2f4b4c7cc1d762361dbec3cd8025387706 (no)
2022-05-13T01:08:18.349762+00:00 heroku[router]: at=info method=GET path="/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6e6a44c62e3827d7e210d52630982c8828a73e4b/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQXZRQmFRTDBBUT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--1644d67e3b1971d7c6c2be43c754947f51bc334d/img_6627-copy.jpg" host=rt-sample-appp.herokuapp.com request_id=06d02bd8-1ebc-4015-8925-63ec84d35cfd fwd="218.110.232.237" dyno=web.1 connect=0ms service=1617ms status=500 bytes=1891 protocol=https
2022-05-13T01:08:18.472939+00:00 app[web.1]: I, [2022-05-13T01:08:18.472865 #20] INFO -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] S3 Storage (967.2ms) Downloaded file from key: d6gum4prxe21jwhticu2jln53k6a
2022-05-13T01:08:18.473979+00:00 app[web.1]: I, [2022-05-13T01:08:18.473941 #20] INFO -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd] Completed 500 Internal Server Error in 1612ms (ActiveRecord: 11.9ms | Allocations: 10440)
2022-05-13T01:08:18.475294+00:00 app[web.1]: F, [2022-05-13T01:08:18.475036 #20] FATAL -- : [06d02bd8-1ebc-4015-8925-63ec84d35cfd]
2022-05-13T01:08:18.475294+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] ArgumentError (wrong number of arguments (given 1, expected 0)):
2022-05-13T01:08:18.475295+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd]
2022-05-13T01:08:18.475295+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] image_processing (1.9.3) lib/image_processing/chainable.rb:66:in `branch'
2022-05-13T01:08:18.475296+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] image_processing (1.9.3) lib/image_processing/chainable.rb:62:in `call'
2022-05-13T01:08:18.475297+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/transformers/image_processing_transformer.rb:15:in `process'
2022-05-13T01:08:18.475298+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/transformers/transformer.rb:25:in `transform'
2022-05-13T01:08:18.475298+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variation.rb:52:in `block in transform'
2022-05-13T01:08:18.475298+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/notifications.rb:182:in `instrument'
2022-05-13T01:08:18.475298+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variation.rb:51:in `transform'
2022-05-13T01:08:18.475299+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variant.rb:105:in `transform'
2022-05-13T01:08:18.475299+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variant.rb:100:in `block in process'
2022-05-13T01:08:18.475299+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/downloader.rb:15:in `block in open'
2022-05-13T01:08:18.475299+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/downloader.rb:24:in `open_tempfile'
2022-05-13T01:08:18.475299+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/downloader.rb:12:in `open'
2022-05-13T01:08:18.475300+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) lib/active_storage/service.rb:87:in `open'
2022-05-13T01:08:18.475300+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/blob.rb:217:in `open'
2022-05-13T01:08:18.475300+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variant.rb:99:in `process'
2022-05-13T01:08:18.475300+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/models/active_storage/variant.rb:67:in `processed'
2022-05-13T01:08:18.475300+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activestorage (6.0.4) app/controllers/active_storage/representations_controller.rb:12:in `show'
2022-05-13T01:08:18.475301+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
2022-05-13T01:08:18.475301+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/abstract_controller/base.rb:195:in `process_action'
2022-05-13T01:08:18.475312+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/rendering.rb:30:in `process_action'
2022-05-13T01:08:18.475313+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
2022-05-13T01:08:18.475313+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/callbacks.rb:135:in `run_callbacks'
2022-05-13T01:08:18.475313+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/abstract_controller/callbacks.rb:41:in `process_action'
2022-05-13T01:08:18.475313+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/rescue.rb:22:in `process_action'
2022-05-13T01:08:18.475313+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
2022-05-13T01:08:18.475314+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/notifications.rb:180:in `block in instrument'
2022-05-13T01:08:18.475314+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2022-05-13T01:08:18.475314+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/notifications.rb:180:in `instrument'
2022-05-13T01:08:18.475314+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
2022-05-13T01:08:18.475314+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
2022-05-13T01:08:18.475315+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activerecord (6.0.4) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
2022-05-13T01:08:18.475315+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/abstract_controller/base.rb:136:in `process'
2022-05-13T01:08:18.475317+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionview (6.0.4) lib/action_view/rendering.rb:39:in `process'
2022-05-13T01:08:18.475317+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal.rb:190:in `dispatch'
2022-05-13T01:08:18.475318+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_controller/metal.rb:254:in `dispatch'
2022-05-13T01:08:18.475318+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
2022-05-13T01:08:18.475318+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/routing/route_set.rb:33:in `serve'
2022-05-13T01:08:18.475318+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/journey/router.rb:49:in `block in serve'
2022-05-13T01:08:18.475319+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/journey/router.rb:32:in `each'
2022-05-13T01:08:18.475319+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/journey/router.rb:32:in `serve'
2022-05-13T01:08:18.475319+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
2022-05-13T01:08:18.475319+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
2022-05-13T01:08:18.475320+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/etag.rb:27:in `call'
2022-05-13T01:08:18.475320+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
2022-05-13T01:08:18.475320+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/head.rb:12:in `call'
2022-05-13T01:08:18.475320+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
2022-05-13T01:08:18.475320+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/cookies.rb:654:in `call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/callbacks.rb:101:in `run_callbacks'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
2022-05-13T01:08:18.475321+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] railties (6.0.4) lib/rails/rack/logger.rb:37:in `call_app'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] railties (6.0.4) lib/rails/rack/logger.rb:26:in `block in call'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/tagged_logging.rb:80:in `block in tagged'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/tagged_logging.rb:28:in `tagged'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/tagged_logging.rb:80:in `tagged'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] railties (6.0.4) lib/rails/rack/logger.rb:26:in `call'
2022-05-13T01:08:18.475322+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/request_id.rb:27:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/method_override.rb:24:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/runtime.rb:22:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] activesupport (6.0.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
2022-05-13T01:08:18.475323+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/static.rb:126:in `call'
2022-05-13T01:08:18.475324+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
2022-05-13T01:08:18.475325+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/ssl.rb:74:in `call'
2022-05-13T01:08:18.475325+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] actionpack (6.0.4) lib/action_dispatch/middleware/host_authorization.rb:76:in `call'
2022-05-13T01:08:18.475325+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] railties (6.0.4) lib/rails/engine.rb:527:in `call'
2022-05-13T01:08:18.475326+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] puma (4.3.6) lib/puma/configuration.rb:228:in `call'
2022-05-13T01:08:18.475326+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] puma (4.3.6) lib/puma/server.rb:713:in `handle_request'
2022-05-13T01:08:18.475326+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] puma (4.3.6) lib/puma/server.rb:472:in `process_client'
2022-05-13T01:08:18.475326+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] puma (4.3.6) lib/puma/server.rb:328:in `block in run'
2022-05-13T01:08:18.475326+00:00 app[web.1]: [06d02bd8-1ebc-4015-8925-63ec84d35cfd] puma (4.3.6) lib/puma/thread_pool.rb:134:in `block in spawn_thread'`
Besides, I can see the uploaded image on the AWS S3 bucket page. So I suppose my setup relating to the Access Key, Secret Key, region and bucket name should be working fine. And yes, I did set the master key as well as credentials just in case.
When I clicked the link of the image on S3 bucket page, I can see it without problem. The image was successfully uploaded to the S3 bucket but I have problem showing it on my app's website.
As to the S3 setup, I copied & pasted shown below from someone's. So, I guess it's correctly setup as "public" as I unchecked the "Block Public Access" box also.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadAllowed",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": "arn:aws:s3:::my-bucket-name/*"
}
]
}
As to the CORS, I also copied & pasted someone's setup as below.
[
{
"AllowedHeaders": [
""
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
"my-app-name.herokuapp.com"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
I tried ACL to check "read" for public access also but it didn't work either. I guess ACL doesn't have anything to do with my problem.
For days, I have been scouring the net for any helpful information but unable to find the solution. If anyone could give me some idea, instruction or direction to solve the problem, it'll be much appreciated. Thank you!
------my code---------------------------------------------------------------
models/micropost.rb
class Micropost < ApplicationRecord
belongs_to :user
has_one_attached :image
default_scope -> { self.order(created_at: :desc) }
validates :user_id, presence: true
validates :content, presence: true, length: { maximum: 140 }
validates :image, content_type: { in: %w[image/jpeg image/gif
image/png],
message: "must be a valid image format" },
size: { less_than: 5.megabytes,
message: "should be less than 5MB" }
def display_image
image.variant(resize_to_limit: [500, 500])
end
end
views/microposts/_micropost.html.erb
<li id="micropost-<%= micropost.id %>">
<%= link_to gravatar_for(micropost.user, size: 50),micropost.user%>
<span class="user"><%= link_to micropost.user.name,micropost.user%>
</span>
<span class="content">
<%= micropost.content %>
<%= image_tag micropost.display_image if
micropost.image.attached? %>
</span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
</span>
</li>
controllers/microposts_controller.rb
class MicropostsController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy
# POST /microposts
def create
@micropost = current_user.microposts.build(micropost_params)
@micropost.image.attach(params[:micropost][:image])
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_url
else
@feed_items = current_user.feed.paginate(page: params[:page])
render 'static_pages/home'
end
end
# DELETE /microposts/:id
def destroy
@micropost.destroy
flash[:success] = "Micropost deleted"
redirect_to request.referrer || root_url
end
private
def micropost_params
params.require(:micropost).permit(:content, :image)
end
def correct_user
@micropost = current_user.microposts.find_by(id: params[:id])
redirect_to root_url if @micropost.nil?
end
end
Solution 1:[1]
Try to change
def display_image
image.variant(resize_to_limit: [500, 500]).processed
end
and call it using image_tag micropost.display_image.url
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Joe |