0.0
No commit activity in last 3 years
No release in over 3 years
This gem hides the details for implementing an image upload view component with crop function.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 9.0
~> 1.3

Runtime

< 5.1, >= 4.2.5
 Project Readme

Gem Version

Upload Image

This Rails gem simplifies the implementation of uploading image. With it, you can write the following line in your *.html.erb as a view component:

<%= upload_image form: f, image_name: :avatar, width: 150, height: 150 %>

Then you will get:

It takes advantages of carrierwave and cropper.js.

Usage

There are some places you need to modify in your Rails app. For example:

  • JavaScript asset file app/assets/javascripts/application.js
//= require upload-image
  • Stylesheet asset file app/assets/stylesheets/application.scss
//= require upload-image
  • Model file
class User < ApplicationRecord
  mount_uploader :avatar, ImageUploader
  include Croppable
end
  • CarrierWave uploader file
class ImageUploader < CarrierWave::Uploader::Base
  include Croppable
  ...
end
  • Controller file
class UsersController < ApplicationController
  include Croppable
  ...
end
  • View file
<%= upload_image form: f, image_name: :avatar, width: 150, height: 150 %>

Then you are good to go.

Installation

Add this line to your application's Gemfile:

gem 'upload-image', '~> 0.1'

And then execute:

$ bundle

Add the require statement in your config/application.rb:

require 'upload-image'

Contributing

Feel free to contribute.

License

The gem is available as open source under the terms of the MIT License.