Last active
August 29, 2015 14:13
-
-
Save cantonic/67f6fa7820b908b936d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class AvatarUploader < CarrierWave::Uploader::Base | |
# Include RMagick or MiniMagick support: | |
# include CarrierWave::RMagick | |
include Cloudinary::CarrierWave | |
# Override the directory where uploaded files will be stored. | |
# This is a sensible default for uploaders that are meant to be mounted: | |
# def store_dir | |
# File.join("uploads", model.class.to_s.underscore, mounted_as.to_s, model.id.to_s) | |
# end | |
# Provide a default URL as a default if there hasn't been a file uploaded: | |
def default_url | |
# ActionController::Base.helpers.asset_path("dummy/"+[version_name, "dummy.png"].compact.join('_')) | |
# had to change this because I got error message 'Asset names passed to helpers should not include the "/assets/" prefix' | |
"dummy/"+[version_name, "dummy.png"].compact.join('_') | |
end | |
def public_id | |
return "user_#{model.id}_avatar" | |
end | |
# Process files as they are uploaded: | |
# process :scale => [200, 300] | |
# | |
# def scale(width, height) | |
# # do something | |
# end | |
# Create different versions of your uploaded files: | |
version :large do | |
resize_to_limit(600,600) | |
end | |
version :square_600 do | |
process :custom_crop | |
end | |
sizes = [600, 300, 128, 64, 32, 16] | |
sizes.each_with_index do |size, index| | |
if size != 600 | |
version "square_#{size}".to_sym, from_version: "square_#{sizes[index-1]}".to_sym do | |
resize_to_fill(size, size) | |
end | |
end | |
end | |
# Add a white list of extensions which are allowed to be uploaded. | |
def extension_white_list | |
%w(jpg jpeg gif png) | |
end | |
# Override the filename of the uploaded files: | |
# Avoid using model.id or version_name here, see uploader/store.rb for details. | |
# def filename | |
# "something.jpg" if original_filename | |
# end | |
def custom_crop | |
return :x => model.avatar_crop_x, :y => model.avatar_crop_y, | |
:width => model.avatar_crop_w, :height => model.avatar_crop_h, | |
:crop => :crop | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sprockets::Rails::Helper::AbsoluteAssetPathError - Asset names passed to helpers should not include the "/assets/" prefix. Instead of "/assets/dummy/square_128_dummy.png", use "dummy/square_128_dummy.png": | |
sprockets-rails (2.2.2) lib/sprockets/rails/helper.rb:200:in `check_errors_for' | |
sprockets-rails (2.2.2) lib/sprockets/rails/helper.rb:89:in `asset_path' | |
actionview (4.1.9) lib/action_view/helpers/asset_url_helper.rb:281:in `image_path' | |
actionview (4.1.9) lib/action_view/helpers/asset_tag_helper.rb:204:in `image_tag' | |
app/views/dashboard/_sidebar.html.haml:4:in `_app_views_dashboard__sidebar_html_haml__2750952092217297060_70096178223680' | |
actionview (4.1.9) lib/action_view/template.rb:145:in `block in render' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `instrument' | |
actionview (4.1.9) lib/action_view/template.rb:339:in `instrument' | |
actionview (4.1.9) lib/action_view/template.rb:143:in `render' | |
xray-rails (0.1.14) lib/xray/engine.rb:33:in `render_with_xray' | |
actionview (4.1.9) lib/action_view/renderer/partial_renderer.rb:306:in `render_partial' | |
actionview (4.1.9) lib/action_view/renderer/partial_renderer.rb:279:in `block in render' | |
actionview (4.1.9) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `instrument' | |
actionview (4.1.9) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument' | |
actionview (4.1.9) lib/action_view/renderer/partial_renderer.rb:278:in `render' | |
actionview (4.1.9) lib/action_view/renderer/renderer.rb:47:in `render_partial' | |
actionview (4.1.9) lib/action_view/renderer/renderer.rb:21:in `render' | |
actionview (4.1.9) lib/action_view/helpers/rendering_helper.rb:32:in `render' | |
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:10:in `block in render_with_haml' | |
haml (4.0.5) lib/haml/helpers.rb:89:in `non_haml' | |
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:10:in `render_with_haml' | |
app/views/dashboard/index.html.haml:4:in `_app_views_dashboard_index_html_haml__184793701215612532_70096125988540' | |
actionview (4.1.9) lib/action_view/template.rb:145:in `block in render' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `instrument' | |
actionview (4.1.9) lib/action_view/template.rb:339:in `instrument' | |
actionview (4.1.9) lib/action_view/template.rb:143:in `render' | |
xray-rails (0.1.14) lib/xray/engine.rb:33:in `render_with_xray' | |
actionview (4.1.9) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template' | |
actionview (4.1.9) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `instrument' | |
actionview (4.1.9) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument' | |
actionview (4.1.9) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template' | |
actionview (4.1.9) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout' | |
actionview (4.1.9) lib/action_view/renderer/template_renderer.rb:53:in `render_template' | |
actionview (4.1.9) lib/action_view/renderer/template_renderer.rb:17:in `render' | |
actionview (4.1.9) lib/action_view/renderer/renderer.rb:42:in `render_template' | |
actionview (4.1.9) lib/action_view/renderer/renderer.rb:23:in `render' | |
actionview (4.1.9) lib/action_view/rendering.rb:99:in `_render_template' | |
actionpack (4.1.9) lib/action_controller/metal/streaming.rb:217:in `_render_template' | |
actionview (4.1.9) lib/action_view/rendering.rb:82:in `render_to_body' | |
actionpack (4.1.9) lib/action_controller/metal/rendering.rb:32:in `render_to_body' | |
actionpack (4.1.9) lib/action_controller/metal/renderers.rb:32:in `render_to_body' | |
actionpack (4.1.9) lib/abstract_controller/rendering.rb:25:in `render' | |
actionpack (4.1.9) lib/action_controller/metal/rendering.rb:16:in `render' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render' | |
activesupport (4.1.9) lib/active_support/core_ext/benchmark.rb:12:in `block in ms' | |
/Users/cantonic/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime' | |
activesupport (4.1.9) lib/active_support/core_ext/benchmark.rb:12:in `ms' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:41:in `block in render' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime' | |
activerecord (4.1.9) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:40:in `render' | |
actionpack (4.1.9) lib/action_controller/metal/implicit_render.rb:10:in `default_render' | |
actionpack (4.1.9) lib/action_controller/metal/implicit_render.rb:5:in `send_action' | |
actionpack (4.1.9) lib/abstract_controller/base.rb:189:in `process_action' | |
actionpack (4.1.9) lib/action_controller/metal/rendering.rb:10:in `process_action' | |
actionpack (4.1.9) lib/abstract_controller/callbacks.rb:20:in `block in process_action' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:113:in `call' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:166:in `block in halting' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:229:in `block in halting' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:229:in `block in halting' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:166:in `block in halting' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:166:in `block in halting' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:86:in `run_callbacks' | |
actionpack (4.1.9) lib/abstract_controller/callbacks.rb:19:in `process_action' | |
actionpack (4.1.9) lib/action_controller/metal/rescue.rb:29:in `process_action' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `block in instrument' | |
activesupport (4.1.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
activesupport (4.1.9) lib/active_support/notifications.rb:159:in `instrument' | |
actionpack (4.1.9) lib/action_controller/metal/instrumentation.rb:30:in `process_action' | |
actionpack (4.1.9) lib/action_controller/metal/params_wrapper.rb:250:in `process_action' | |
activerecord (4.1.9) lib/active_record/railties/controller_runtime.rb:18:in `process_action' | |
actionpack (4.1.9) lib/abstract_controller/base.rb:136:in `process' | |
actionview (4.1.9) lib/action_view/rendering.rb:30:in `process' | |
actionpack (4.1.9) lib/action_controller/metal.rb:196:in `dispatch' | |
actionpack (4.1.9) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' | |
actionpack (4.1.9) lib/action_controller/metal.rb:232:in `block in action' | |
actionpack (4.1.9) lib/action_dispatch/routing/route_set.rb:82:in `dispatch' | |
actionpack (4.1.9) lib/action_dispatch/routing/route_set.rb:50:in `call' | |
actionpack (4.1.9) lib/action_dispatch/journey/router.rb:73:in `block in call' | |
actionpack (4.1.9) lib/action_dispatch/journey/router.rb:59:in `call' | |
actionpack (4.1.9) lib/action_dispatch/routing/route_set.rb:685:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
xray-rails (0.1.14) lib/xray/middleware.rb:37:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/rack/agent_hooks.rb:26:in `traced_call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/rack/developer_mode.rb:48:in `traced_call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call' | |
rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call' | |
rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
warden (1.2.3) lib/warden/manager.rb:35:in `block in call' | |
warden (1.2.3) lib/warden/manager.rb:34:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/etag.rb:23:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/head.rb:11:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/params_parser.rb:27:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/flash.rb:254:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context' | |
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/cookies.rb:562:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
activerecord (4.1.9) lib/active_record/query_cache.rb:36:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
activerecord (4.1.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
activerecord (4.1.9) lib/active_record/migration.rb:380:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' | |
activesupport (4.1.9) lib/active_support/callbacks.rb:82:in `run_callbacks' | |
actionpack (4.1.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/reloader.rb:73:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/remote_ip.rb:76:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call' | |
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call' | |
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
railties (4.1.9) lib/rails/rack/logger.rb:38:in `call_app' | |
railties (4.1.9) lib/rails/rack/logger.rb:20:in `block in call' | |
activesupport (4.1.9) lib/active_support/tagged_logging.rb:68:in `block in tagged' | |
activesupport (4.1.9) lib/active_support/tagged_logging.rb:26:in `tagged' | |
activesupport (4.1.9) lib/active_support/tagged_logging.rb:68:in `tagged' | |
railties (4.1.9) lib/rails/rack/logger.rb:20:in `call' | |
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
request_store (1.1.0) lib/request_store/middleware.rb:8:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/request_id.rb:21:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/runtime.rb:17:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
activesupport (4.1.9) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/lock.rb:17:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
actionpack (4.1.9) lib/action_dispatch/middleware/static.rb:84:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/sendfile.rb:112:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
railties (4.1.9) lib/rails/engine.rb:514:in `call' | |
railties (4.1.9) lib/rails/application.rb:144:in `call' | |
newrelic_rpm (3.9.6.257) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call' | |
rack (1.5.2) lib/rack/lock.rb:17:in `call' | |
rack (1.5.2) lib/rack/content_length.rb:14:in `call' | |
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' | |
/Users/cantonic/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' | |
/Users/cantonic/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' | |
/Users/cantonic/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/assets/images | |
|-- dummy | |
| |-- dummy.png | |
| |-- square_128_dummy.png | |
| |-- square_16_dummy.png | |
| |-- square_300_dummy.png | |
| |-- square_32_dummy.png | |
| |-- square_600_dummy.png | |
| `-- square_64_dummy.png | |
`-- logo328x102.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection @users, object_root: false | |
attributes :id, :unique_id, :name | |
node :thumbnail do |u| | |
# u.avatar.square_32.url results in http://localhost:3000/gradebook/courses/6/dummy/square_32_dummy.png | |
image_path(u.avatar.square_32) # results in http://localhost:3000/images/dummy/square_32_dummy.png | |
end | |
node :tokens do |u| | |
[u.unique_id, u.first_name, u.last_name, u.email] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment