simple-image-uploader 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 898376aa43442a7be4b30d15fbfd3466d95e4f55
4
+ data.tar.gz: d007c305568061c48de3f5c54188a61a2bae0461
5
+ SHA512:
6
+ metadata.gz: 697f17c2dafdb76b7a514cb32ff2ac8303a8c3cf0368f5ba674825517c4283dc0c8477b54464bc696a6bb4a25aa695eb8d2e04a3505f41fbeaebb59888dce69e
7
+ data.tar.gz: c26e77e1ed5673290dd4243506e360a0c82bf511fccb883178bfb7d2d5ee72545363a8eee00152d06f10cc2b1af080e501281cabb5214be68ab4dfa8a1178a57
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/designium/simple-image-uploader)
4
4
 
5
- simple-image-uploader is a Rails 3 generator that creates a small scaffold class called Image. It enables image upload feature to your web app at no time.
5
+ simple-image-uploader is a Rails 4 generator that creates a small scaffold class called Image. It enables image upload feature to your web app at no time. If you need the simple-image-uploader for Rails 3, please go to version 0.14. The Rails 4 version has significant changes.
6
6
 
7
7
  # Demo
8
8
 
@@ -4,9 +4,9 @@ module SimpleImageUploader
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  def create_image_model
7
- generate("model", "image description:string file:string")
7
+ generate("model", "image file:string imageable_id:integer imageable_type:string")
8
8
  rake("db:migrate")
9
- remove_file "image.rb", "app/models/image.rb"
9
+ remove_file "app/models/image.rb"
10
10
  end
11
11
 
12
12
  def generate_image_everything
@@ -1,3 +1,3 @@
1
1
  class ApplicationController < ActionController::Base
2
- protect_from_forgery
2
+ protect_from_forgery with: :exception
3
3
  end
@@ -29,7 +29,7 @@ class FileUploader < CarrierWave::Uploader::Base
29
29
  # end
30
30
 
31
31
  # Process files as they are uploaded:
32
- process :resize_and_pad => [500, 500, 'white' ]
32
+ # process :resize_and_pad => [500, 500, 'white' ]
33
33
  #
34
34
  # def scale(width, height)
35
35
  # # do something
@@ -1,7 +1,5 @@
1
1
  class Image < ActiveRecord::Base
2
- attr_accessible :description, :file, :remove_file
3
-
4
- validates :description, :length => { maximum: 150 }
2
+ belongs_to :imageable, polymorphic: true # You can use Image class with any other model you have.
5
3
 
6
4
  mount_uploader :file, FileUploader
7
5
  end
@@ -1,8 +1,4 @@
1
1
  <%= form_for @image, html: { multipart: true } do |f| %>
2
- <p>
3
- <%= f.label :description %><br />
4
- <%= f.text_field :description %>
5
- </p>
6
2
  <p>
7
3
  <%= f.label :file %><br />
8
4
  <%= f.file_field :file %>
@@ -1,12 +1,10 @@
1
1
 
2
2
  <table>
3
3
  <tr>
4
- <th>Description</th>
5
4
  <th>File</th>
6
5
  </tr>
7
6
  <% for image in @images %>
8
7
  <tr>
9
- <td><%= image.description %></td>
10
8
  <td><%= image_tag image.file %></td>
11
9
  <td><%= link_to "Show", image %></td>
12
10
  <td><%= link_to "Edit", edit_image_path(image) %></td>
@@ -1,8 +1,3 @@
1
-
2
- <p>
3
- <strong>Description:</strong>
4
- <%= @image.description %>
5
- </p>
6
1
  <p>
7
2
  <strong>Image:</strong>
8
3
  <%= image_tag @image.file %>
@@ -1,42 +1,70 @@
1
1
  class ImagesController < ApplicationController
2
+ before_action :set_image, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /images
5
+ # GET /images.json
2
6
  def index
3
7
  @images = Image.all
4
8
  end
5
9
 
10
+ # GET /images/1
11
+ # GET /images/1.json
6
12
  def show
7
- @image = Image.find(params[:id])
8
13
  end
9
14
 
15
+ # GET /images/new
10
16
  def new
11
17
  @image = Image.new
12
18
  end
13
19
 
14
- def create
15
- @image = Image.new(params[:image])
16
- if @image.save
17
- redirect_to @image, :notice => "Successfully created image."
18
- else
19
- render :action => 'new'
20
- end
20
+ # GET /images/1/edit
21
+ def edit
21
22
  end
22
23
 
23
- def edit
24
- @image = Image.find(params[:id])
24
+ # POST /images
25
+ def create
26
+ @image = Image.new(image_params)
27
+
28
+ respond_to do |format|
29
+ if @image.save
30
+ format.html { redirect_to @image, notice: 'Image was successfully created.' }
31
+ format.json { render action: 'show', status: :created, location: @image }
32
+ else
33
+ format.html { render action: 'new' }
34
+ end
35
+ end
25
36
  end
26
37
 
38
+ # PATCH/PUT /images/1
27
39
  def update
28
- @image = Image.find(params[:id])
29
- if @image.update_attributes(params[:image])
30
- redirect_to @image, :notice => "Successfully updated image."
31
- else
32
- render :action => 'edit'
40
+ respond_to do |format|
41
+ if @image.update(image_params)
42
+ format.html { redirect_to @image, notice: 'Image was successfully updated.' }
43
+ format.json { head :no_content }
44
+ else
45
+ format.html { render action: 'edit' }
46
+ end
33
47
  end
34
48
  end
35
49
 
50
+ # DELETE /images/1
51
+ # DELETE /images/1.json
36
52
  def destroy
37
- @image = Image.find(params[:id])
38
- @image.remove_file!
39
53
  @image.destroy
40
- redirect_to images_url, :notice => "Successfully destroyed image."
54
+ respond_to do |format|
55
+ format.html { redirect_to images_url }
56
+ format.json { head :no_content }
57
+ end
41
58
  end
59
+
60
+ private
61
+ # Use callbacks to share common setup or constraints between actions.
62
+ def set_image
63
+ @image = Image.find(params[:id])
64
+ end
65
+
66
+ # Never trust parameters from the scary internet, only allow the white list through.
67
+ def image_params
68
+ params.require(:image).permit(:file, :imageable_id, :imageable_type)
69
+ end
42
70
  end
@@ -1,7 +1,7 @@
1
1
  module Simple
2
2
  module Image
3
3
  module Uploader
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-image-uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chim Kan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
11
+ date: 2013-12-28 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! 'simple-image-uploader creates Image scaffold with file upload and
15
- removal. It is based on carrierwave and mini-imagegick gems. Image model, controller
16
- and form are have simple code that allows any application to use image upload immediately.
13
+ description: 'simple-image-uploader creates Image scaffold with file upload and removal.
14
+ It is based on carrierwave and mini-imagegick gems. Image model, controller and
15
+ form are have simple code that allows any application to use image upload immediately.
17
16
  Add simple-image-uploader gem to your Gemfile. Run bundle install. Then run ''rails
18
17
  g simple_image_uploader''. Run rails s and check http://localhost:3000/images. '
19
18
  email: designium+simple@gmail.com
@@ -21,6 +20,11 @@ executables: []
21
20
  extensions: []
22
21
  extra_rdoc_files: []
23
22
  files:
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/rails/generators/simple_image_uploader/USAGE
24
28
  - lib/rails/generators/simple_image_uploader/simple_image_uploader_generator.rb
25
29
  - lib/rails/generators/simple_image_uploader/templates/application_controller.rb
26
30
  - lib/rails/generators/simple_image_uploader/templates/file_uploader.rb
@@ -31,36 +35,30 @@ files:
31
35
  - lib/rails/generators/simple_image_uploader/templates/images/new.html.erb
32
36
  - lib/rails/generators/simple_image_uploader/templates/images/show.html.erb
33
37
  - lib/rails/generators/simple_image_uploader/templates/images_controller.rb
34
- - lib/rails/generators/simple_image_uploader/USAGE
35
- - lib/simple-image-uploader/version.rb
36
38
  - lib/simple-image-uploader.rb
37
- - Gemfile
38
- - LICENSE
39
- - Rakefile
40
- - README.md
39
+ - lib/simple-image-uploader/version.rb
41
40
  homepage: https://github.com/designium/simple-image-uploader
42
41
  licenses: []
43
- post_install_message: ! '***************************************'
42
+ metadata: {}
43
+ post_install_message: "***************************************"
44
44
  rdoc_options: []
45
45
  require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
48
  requirements:
50
- - - ! '>='
49
+ - - ">="
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
53
  requirements:
56
- - - ! '>='
54
+ - - ">="
57
55
  - !ruby/object:Gem::Version
58
56
  version: '0'
59
57
  requirements: []
60
58
  rubyforge_project:
61
- rubygems_version: 1.8.23
59
+ rubygems_version: 2.2.0
62
60
  signing_key:
63
- specification_version: 3
61
+ specification_version: 4
64
62
  summary: simple-image-uploader allows you to upload images to your Rails 3 app immediately
65
63
  with minimum of effort.
66
64
  test_files: []