Skip to content

dongli/upload-image

Repository files navigation

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.

About

This is Rails gem for simplify the implementation of uploading image.

Resources

License

Stars

Watchers

Forks

Packages

No packages published