Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method when running recreate_versions! #26

Open
norcali opened this issue Mar 29, 2017 · 0 comments
Open

Undefined method when running recreate_versions! #26

norcali opened this issue Mar 29, 2017 · 0 comments

Comments

@norcali
Copy link

norcali commented Mar 29, 2017

Using Dropbox as a storage with CarrierWave I'm trying to add a crop funtionality but when I try to update the attachment to upload I get
undefined method `read' for #CarrierWave::Storage::Dropbox::File:0x007ff74d572528

when trying to use recreate_versions! on the uploader, as far as I've gathered the problem is that the class CarrierWave::Storage::Dropbox::File does not have the methods from the Carrierwave base needed to run recreate_versions!

is this a bug? or is it a feature that was never done?

Below I have every relevant file, hope someone can give me a pointer.

class IssueObservation < ActiveRecord::Base
	attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
	mount_uploader :attachment, AttachmentUploader
	self.table_name = "IssueObservation"
	after_update :crop_attachment

  def crop_attachment
    attachment.recreate_versions! if crop_x.present?
  end
end
class AttachmentUploader < CarrierWave::Uploader::Base
	include CarrierWave::RMagick
  storage :dropbox

  version :thumb do
  	process :crop
	  resize_to_fill(100, 100)
	end

	version :large do
	  resize_to_limit(600, 600)
	end

	def crop
    if model.crop_x.present?
      resize_to_limit(600, 600)
      manipulate! do |img|
        x = model.crop_x
        y = model.crop_y
        w = model.crop_w
        h = model.crop_h
        img.crop!(x, y, w, h)
      end
    end
  end
  
  def store_dir
    "prueba/#{model.user_login}_#{model.id}"
  end

end
<h1>Crop Avatar</h1>
<%= image_tag @observation.attachment_url, id: "cropbox" %>
<h4>Preview</h4>
<div style="width:100px; height:100px; overflow:hidden">
  <%= image_tag @observation.attachment_url, :id => "preview" %>
</div>
<%= form_for @observation do |f| %>
  <% %w[x y w h].each do |attribute| %>
    <%= f.text_field "crop_#{attribute}" %>
  <% end %>
  <div class="actions">
    <%= f.submit "Crop" %>
  </div>
<% end %>
source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

gem 'sqlite3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use sqlite3 as the database for Active Record
gem "mysql2", "~> 0.4.5"
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.3.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views

gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem "twitter-bootstrap-rails"
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'rails_admin', '~> 1.1.1'
gem 'rails_admin_material'
gem 'carrierwave'
gem 'carrierwave-dropbox'
gem 'rmagick'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
class IssueObservationsController < ApplicationController
	def update
	  @observation = IssueObservation.find(params[:id])
	  if @observation.update_attributes(issue_observation_params)
	    if issue_observation_params[:attachment].present?
	      render :crop
	    else
	      redirect_to rails_admin.show_path(model_name: @observation.class.name, id: @observation), notice: "Successfully updated observation."
	    end
	  else
	    render :new
	  end
	end
end
NoMethodError in IssueObservationsController#update
undefined method `read' for #<CarrierWave::Storage::Dropbox::File:0x007ff74e6dd6c8>

Extracted source (around line #11):
9
10
11
12
13
              

  def crop_attachment
    attachment.recreate_versions! if crop_x.present?
  end
end

Rails.root: /home/lhdev1/Projects/unfortracker

Application Trace | Framework Trace | Full Trace
carrierwave (0.11.2) lib/carrierwave/uploader/cache.rb:89:in `sanitized_file'
carrierwave (0.11.2) lib/carrierwave/uploader/cache.rb:128:in `cache!'
carrierwave (0.11.2) lib/carrierwave/uploader/versions.rb:226:in `recreate_versions!'
app/models/issue_observation.rb:11:in `crop_attachment'
activesupport (5.0.2) lib/active_support/callbacks.rb:382:in `block in make_lambda'
activesupport (5.0.2) lib/active_support/callbacks.rb:207:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:207:in `block in halting_and_conditional'
activesupport (5.0.2) lib/active_support/callbacks.rb:456:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:456:in `block in call'
activesupport (5.0.2) lib/active_support/callbacks.rb:456:in `each'
activesupport (5.0.2) lib/active_support/callbacks.rb:456:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_update_callbacks'
activerecord (5.0.2) lib/active_record/callbacks.rb:306:in `_update_record'
activerecord (5.0.2) lib/active_record/timestamp.rb:81:in `_update_record'
activerecord (5.0.2) lib/active_record/persistence.rb:540:in `create_or_update'
activerecord (5.0.2) lib/active_record/callbacks.rb:298:in `block in create_or_update'
activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_save_callbacks'
activerecord (5.0.2) lib/active_record/callbacks.rb:298:in `create_or_update'
activerecord (5.0.2) lib/active_record/persistence.rb:125:in `save'
activerecord (5.0.2) lib/active_record/validations.rb:44:in `save'
activerecord (5.0.2) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (5.0.2) lib/active_record/transactions.rb:319:in `block (2 levels) in save'
activerecord (5.0.2) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
activerecord (5.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `transaction'
activerecord (5.0.2) lib/active_record/transactions.rb:211:in `transaction'
activerecord (5.0.2) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
activerecord (5.0.2) lib/active_record/transactions.rb:319:in `block in save'
activerecord (5.0.2) lib/active_record/transactions.rb:334:in `rollback_active_record_state!'
activerecord (5.0.2) lib/active_record/transactions.rb:318:in `save'
activerecord (5.0.2) lib/active_record/suppressor.rb:41:in `save'
activerecord (5.0.2) lib/active_record/persistence.rb:267:in `block in update'
activerecord (5.0.2) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
activerecord (5.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
activerecord (5.0.2) lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
activerecord (5.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
activerecord (5.0.2) lib/active_record/transactions.rb:211:in `transaction'
activerecord (5.0.2) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
activerecord (5.0.2) lib/active_record/persistence.rb:265:in `update'
app/controllers/issue_observations_controller.rb:13:in `update'
actionpack (5.0.2) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.2) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.2) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.2) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.2) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.2) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack-pjax (1.0.0) lib/rack/pjax.rb:12:in `call'
remotipart (1.3.1) lib/remotipart/middleware.rb:32:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.2) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.2) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.5.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `call'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Request

Parameters:

{"utf8"=>"✓",
 "_method"=>"patch",
 "authenticity_token"=>"vWSzzeqpPvW5btjlQLy0j3/XewHNw4GfhHBLdeQ28bnqJLDrJCwzFZAe9+N2zXxEQUYEx+ihZJkO5jpu7prCxA==",
 "issue_observation"=>{"crop_x"=>"8", "crop_y"=>"30", "crop_w"=>"242", "crop_h"=>"242"},
 "commit"=>"Crop",
 "id"=>"6"}

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant