pushtype / push_type

PushType is a modern, open source content management system for Ruby on Rails.
http://www.pushtype.org
Other
290 stars 32 forks source link

Error inserting media in post when using s3 #23

Closed alexbrinkman closed 7 years ago

alexbrinkman commented 7 years ago

I'm trying to point my media library to s3 and I run into an error when trying to insert an image into a node. The UI shows a message: "Something went wrong. Please try again." The actual file does end up in my media library, but not in the node that I'm trying to insert it into. I don't have the same issue when using :file for the dragonfly datastore.

Here is the error from the log:

NoMethodError (undefined method `media_path' for #<PushType::Admin::AssetsController:0x007ff764d79f70>):
  push_type_admin (0.10.0) app/controllers/push_type/admin/assets_controller.rb:41:in `block (2 levels) in upload'
  actionpack (4.2.7) lib/action_controller/metal/mime_responds.rb:217:in `respond_to'
  push_type_admin (0.10.0) app/controllers/push_type/admin/assets_controller.rb:38:in `upload'
  actionpack (4.2.7) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.2.7) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.7) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.7) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.7) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.7) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
  activesupport (4.2.7) lib/active_support/callbacks.rb:505:in `call'
  activesupport (4.2.7) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
  activesupport (4.2.7) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
  activesupport (4.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.7) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.7) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.7) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.7) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.7) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.7) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.7) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.7) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.7) lib/action_view/rendering.rb:30:in `process'
  rack-mini-profiler (0.10.1) lib/mini_profiler/profiling_methods.rb:102:in `block in profile_method'
  actionpack (4.2.7) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.7) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.7) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:817:in `call'
  railties (4.2.7) lib/rails/engine.rb:518:in `call'
  railties (4.2.7) lib/rails/railtie.rb:194:in `public_send'
  railties (4.2.7) lib/rails/railtie.rb:194:in `method_missing'
  actionpack (4.2.7) lib/action_dispatch/routing/mapper.rb:51:in `serve'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:817:in `call'
  /Users/brinkman/.rvm/gems/ruby-2.3.1@cscl/bundler/gems/recurring_select-4fc9608c69c1/app/middleware/recurring_select_middleware.rb:24:in `call'
  dragonfly (1.0.12) lib/dragonfly/middleware.rb:14:in `call'
  bullet (5.1.1) lib/bullet/rack.rb:12:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (1.6.5) lib/rack/etag.rb:24:in `call'
  rack (1.6.5) lib/rack/conditionalget.rb:38:in `call'
  rack (1.6.5) lib/rack/head.rb:13:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.5) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.5) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.7) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  activerecord (4.2.7) lib/active_record/migration.rb:377:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.7) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.7) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  rollbar (2.12.0) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
  rollbar (2.12.0) lib/rollbar.rb:735:in `scoped'
  rollbar (2.12.0) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  rollbar (2.12.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
  web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.7) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.7) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.7) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.7) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.7) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.5) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.5) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.7) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  dragonfly (1.0.12) lib/dragonfly/cookie_monster.rb:9:in `call'
  rack (1.6.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.7) lib/action_dispatch/middleware/static.rb:120:in `call'
  rack (1.6.5) lib/rack/sendfile.rb:113:in `call'
  rack-mini-profiler (0.10.1) lib/mini_profiler/profiler.rb:278:in `call'
  railties (4.2.7) lib/rails/engine.rb:518:in `call'
  railties (4.2.7) lib/rails/application.rb:165:in `call'
  rack (1.6.5) lib/rack/lock.rb:17:in `call'
  rack (1.6.5) lib/rack/content_length.rb:15:in `call'
  rack (1.6.5) lib/rack/handler/webrick.rb:88:in `service'
aaronrussell commented 7 years ago

@alexbrinkman I've had a quick look in to this. Stumped again. I can't think of any reason why the dragonfly datastore would make a difference. And most of our sites use the s3 datastore too and we're not seeing this problem.

The error seems to suggest that the new PushType::MediaUrlHelper is not available in the PushType::Admin::AssetsController for some reason. Maybe we need to be explicitly including the helper module. I'm guessing from your logs you're on rails 4.2.x - is that right? If so, maybe there's some differences to how helpers are included between 4.2.x and 5.0.0.

aaronrussell commented 7 years ago

In your application config, have you set config.action_controller.include_all_helpers = false anywhere?

alexbrinkman commented 7 years ago

Yes, we are on Rails 4.2.7. I have not set config.action_controller.include_all_helpers anywhere. If I open the console and run Rails.application.config.action_controller.include_all_helpers, I get nil.

alexbrinkman commented 7 years ago

@aaronrussell I've been trying to dig into this issue a bit more. I think you're right that being able to call a helper right from a controller is new in Rails 5, and that it doesn't work in Rails 4. I added include PushType::MediaUrlHelper and also had to include ActionView::Helpers::AssetUrlHelper to the AssetsController and it works, but I don't think that's the actual real solution. Ideas?

Also, I think I was wrong that using :file for the dragonfly_datastore made any difference. I can't get it to work either way now. Sorry, I think that information was misleading.

aaronrussell commented 7 years ago

@alexbrinkman I've just released a new version - 0.10.1 - which I hope resolves this issue.

This is a bit of a weird one. PushType has been accessing the helpers in the controllers via the view_context method which has been around since Rails 3. I tried to recreate the issue with Rails 4.2.7 but it was working fine. Looking in to it I think calling view_context instantiates a new view context every time so you don't actually get the same context your views are using. I have no idea why that meant it wasn't working for you but it feels like it's perhaps an unreliable way of using helpers in a controller. So have opted for a more explicit "including" of helpers modules where needed.

alexbrinkman commented 7 years ago

Thanks, that seems to have fixed the issue! I like the removal of the delay too, that's certainly noticeable.