multiple_files_by_pete 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aac6d941ad34cf9d92aa4902f067f00f1e54650206adc833b9cd4fec2b74e4ef
4
- data.tar.gz: 6ed6be9196422f609f2f912e294e1fb3a973f68540535e745e682652ae186a43
3
+ metadata.gz: 58e95ca2a7501fe64ea531413ba520debf93db0a5093a2f24ce3999f9cb538e1
4
+ data.tar.gz: aa63218454cdb700efb0eeffe37a7bcc90d365e72c3a89c747464a31c38ed012
5
5
  SHA512:
6
- metadata.gz: cd4df6185c93754bc01f5d4ad01ab421905202cb8a077e9cd17783f98db6f741e3ec26eda9b2f9f64fd6eff03cbf95b843b7ee72781d9dec4281675257d7502e
7
- data.tar.gz: a379682deaf49903c956a3c189dd4b293b8d23604a871d37dad5a96613d278d627eb986547d1bd8ca4d6e5546b146dc52f23f3b9aa3c60397a4b370c3c1092b2
6
+ metadata.gz: e7d3c800a22d907f8161e44d3c7437ca4372ffe268a719e6733959689c9cfe685bc218556b89f5cfafb3191b89b7e0ba010bfd67ed4e5ab6b9ff904541833099
7
+ data.tar.gz: 5ebfc7c05c4c47f0ab561c32c891eacc9bf783b3f1b28711f9c6b6fe10229748e69d53d9ef29f795851d88b3dd87260c6499054d66e5ec12f2ff8036efdf9453
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
- # MultipleFilesByPete
1
+ # Ruby On Rails multiple files by Pete
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/multiple_files_by_pete`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ An agile way to implement multiple files uploads in a Ruby On Rails scaffold without the need to create additional tables
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
6
  ## Installation
8
7
 
@@ -16,24 +15,98 @@ And then execute:
16
15
 
17
16
  $ bundle install
18
17
 
19
- Or install it yourself as:
18
+ ## Support
20
19
 
21
- $ gem install multiple_files_by_pete
20
+ Ruby On Rails: 5, 6, 7
21
+
22
+ This gem does not work with SQLite database
22
23
 
23
24
  ## Usage
25
+ Let's create a example for a Place scaffold:
26
+
27
+ 1. Let's create a new rails app:
28
+
29
+ ```ruby
30
+ rails new myapp --database=postgresql
31
+ ```
32
+
33
+ 2. Create the database:
34
+
35
+ ```ruby
36
+ bundle exec rake db:create
37
+ ```
38
+
39
+ 3. Go to your application's directory in Terminal and run the command:
40
+
41
+ ```ruby
42
+ bundle exec rails g scaffold Place name:string description:text
43
+ ```
44
+
45
+ 4. Add this line to your application's Gemfile:
46
+
47
+ ```ruby
48
+ gem 'multiple_files_by_pete'
49
+ ```
50
+
51
+ 5. Go to your application's directory in Terminal and run:
52
+
53
+ ```ruby
54
+ bundle install
55
+ ```
56
+
57
+ 6. 6. Go to the application directory in Terminal and run the following command to install the necessary code and files from the gem:
58
+
59
+ ```ruby
60
+ bundle exec rake 'multiple_files_by_pete[place]'
61
+ ```
62
+
63
+ 7. Add jQuery to your layout file:
64
+
65
+ ```html
66
+ <script src='/multiple_files_by_pete/jquery-3.6.0.min.js'></script>
67
+ ```
68
+
69
+ 8. Add bootstrap.min.css to your layout file:
70
+
71
+ ```html
72
+ <link rel="stylesheet" href="/multiple_files_by_pete/bootstrap.min.css">
73
+ ```
74
+
75
+ 9. Copy and paste this code to get all the object files. For this example paste it in the edit action of the places_controller.rb file
76
+
77
+ ```ruby
78
+ @files = PeteFile.get_object_files(@place)
79
+ ```
80
+
81
+ 10. Copy paste this code for each file field you need, you can add as many as you want by changing the section variable. For this example paste it into the /places/_form.html.erb file:
82
+
83
+ ```ruby
84
+
85
+ <%= render partial: 'shared/files_by_pete', locals: {model: @place, files: @files, section: 'legal_files' ,label: 'Upload legal files'} %>
86
+
87
+ <%= render partial: 'shared/files_by_pete', locals: {model: @place, files: @files, section: 'extra_files' ,label: 'Upload extra files'} %>
88
+
89
+ ```
90
+
91
+ 11. Copy and paste this code at the end of the form where you have added the file fields. The size limit is in MB. For this example paste it in the file /places/_form.html.erb:
92
+
93
+ ```ruby
94
+ <%= render 'shared/files_by_pete_js', model: @place, size_limit: 50%>
95
+ ```
96
+
97
+ Video Tutorial
98
+ ===============
24
99
 
25
- TODO: Write usage instructions here
100
+ Watch this video to see how it works
26
101
 
27
- ## Development
102
+ [![IMAGE ALT TEXT HERE](https://raw.githubusercontent.com/peterconsuegra/multiple_files_by_pete/master/templates/multiple_files_by_pete.png)](https://www.youtube.com/watch?v=Oy5W9dalN9M)
28
103
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
104
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
105
 
33
106
  ## Contributing
34
107
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/multiple_files_by_pete. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
108
+ Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/multiple_files_by_pete. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/peterconsuegra/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
36
109
 
37
110
  ## Code of Conduct
38
111
 
39
- Everyone interacting in the MultipleFilesByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
112
+ Everyone interacting in the MultipleFilesByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterconsuegra/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MultipleFilesByPete
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -1,12 +1,13 @@
1
1
  require_relative '../peterconsuegra_recipes'
2
+ require 'colorize'
2
3
 
3
- #bundle exec rake 'multiple_files_by_pete[place]'
4
+ #bundle exec rake 'multiple_files_by_pete[model]'
4
5
 
5
6
  desc 'install multiple_files_by_pete required files'
6
7
 
7
8
  task :multiple_files_by_pete, [:model] do |t, args|
8
9
 
9
- #Require all app models
10
+ #Require all models
10
11
  Dir.glob("#{Rails.root}/app/models/*.rb").each { |file| require file }
11
12
 
12
13
  #Base routes
@@ -20,19 +21,19 @@ task :multiple_files_by_pete, [:model] do |t, args|
20
21
  #Adding partials
21
22
  PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/app/views/shared/",["_files_by_pete_js.html.erb","_files_by_pete.html.erb"])
22
23
 
23
- #Adding concern
24
+ #Adding concern file
24
25
  PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/controllers/concerns/","files_by_pete.rb")
25
26
 
26
- #Adding route to routes.rb
27
+ #Adding js and css assets
28
+ PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/public/multiple_files_by_pete/",["jquery-3.6.0.min.js","bootstrap.min.css"])
29
+
30
+ #Adding route
27
31
  PeterConsuegraRecipes::add_route(hash['base_route'],"pete_file_upload","post")
28
32
  PeterConsuegraRecipes::add_route(hash['base_route'],"pete_file_destroy","post")
29
33
 
30
34
  #Adding concern to controller
31
35
  PeterConsuegraRecipes::add_concern_to_controller("include FilesByPete\n",hash['controller_file'],hash['controller_class'])
32
36
 
33
- #Adding layouts files
34
- PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/public/multiple_files_by_pete/",["jquery-3.6.0.min.js","bootstrap.min.css"])
35
-
36
37
  puts "-----------------------------------------".red
37
38
  puts "Copy and paste this code in your project".red
38
39
  puts "-----------------------------------------".red
@@ -47,9 +48,13 @@ task :multiple_files_by_pete, [:model] do |t, args|
47
48
  puts "<%= render partial: 'shared/files_by_pete', locals: {model: @#{args[:model]}, files: @files, section: 'extra_files' ,label: 'Upload extra files'} %>".red
48
49
  puts "Add the JS logic for multiple_file_by_pete to your _form.html.erb file:".red
49
50
  puts "<%= render 'shared/files_by_pete_js', model: @#{args[:model]}, size_limit: 50%>".red
50
-
51
+
52
+ puts "Running command:".blue
53
+ puts "rails g model PeteFile section:string attachable_id:integer attachable_type:string name:string".green
51
54
  `rails g model PeteFile section:string attachable_id:integer attachable_type:string name:string`
52
55
  sleep 2
56
+ puts "Running command:".blue
57
+ puts "rake db:migrate".green
53
58
  `rake db:migrate`
54
59
 
55
60
  #Adding model pete_file.rb
Binary file
@@ -1,32 +1,31 @@
1
-
2
1
  <%if model.persisted?%>
3
2
 
4
- <%
5
- attachable_id = model.id
6
- attachable_type = model.class.name
7
- uniqid= rand(36**8).to_s(36)
8
- section_files = files[section]
9
-
10
- %>
11
-
12
- <div id="upload_brief_area" class="upload_brief_file">
3
+ <%
4
+ attachable_id = model.id
5
+ attachable_type = model.class.name
6
+ uniqid= rand(36**8).to_s(36)
7
+ section_files = files[section]
13
8
 
14
- <p style="margin-bottom: 10px;margin-top:30px "><%=label%> </p>
9
+ %>
15
10
 
16
- <ul id="section_<%=section%>" style="margin-left: 20px">
17
- <%unless section_files.nil?%>
18
- <% section_files.each do |pete_file| %>
19
- <li id="pete_file_<%=pete_file.id%>"><%=pete_file.get_file_a.html_safe%> <a pete_file_id="<%=pete_file.id%>" style="color:red" class="delete_file" href="#">X</a></li>
20
- <%end%>
21
- <%end%>
22
- </ul>
11
+ <div class ="row">
12
+ <div class="col-12 mt-3 mb-3">
13
+ <div id="upload_brief_area_<%=section%>" class="upload_brief_file">
14
+
15
+ <p style="margin-bottom: 10px;margin-top:30px "><%=label%> </p>
16
+
17
+ <ul id="section_<%=section%>" style="margin-left: 20px">
18
+ <%unless section_files.nil?%>
19
+ <% section_files.each do |pete_file| %>
20
+ <li id="pete_file_<%=pete_file.id%>"><%=pete_file.get_file_a.html_safe%> <a pete_file_id="<%=pete_file.id%>" style="color:red" class="delete_file" href="#">X</a></li>
21
+ <%end%>
22
+ <%end%>
23
+ </ul>
24
+
25
+ <input type="file" id="<%=uniqid%>" section="<%=section%>" name="file" class="Uploadid" multiple="">
23
26
 
24
- <form action="/upload_files_by_pete" method="POST" class="form-horizontal frm-logoUpload" enctype="multipart/form-data">
25
-
26
- <input type="file" id="<%=uniqid%>" section="<%=section%>" name="file" class="Uploadid" multiple="">
27
-
28
- </form>
29
-
30
- </div>
27
+ </div>
28
+ </div>
29
+ </div>
31
30
 
32
31
  <%end%>
@@ -107,7 +107,7 @@
107
107
  upload_progress_html += '</div>';
108
108
 
109
109
 
110
- $("#upload_brief_area").prepend(upload_progress_html);
110
+ $("#upload_brief_area_"+section).prepend(upload_progress_html);
111
111
 
112
112
  $.ajax({
113
113
  xhr: function()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiple_files_by_pete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Consuegra
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-02 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -61,12 +61,14 @@ files:
61
61
  - lib/railtie.rb
62
62
  - lib/tasks/multiple_files_by_pete.rake
63
63
  - multiple_files_by_pete-0.2.0.gem
64
+ - multiple_files_by_pete-0.2.1.gem
64
65
  - multiple_files_by_pete.gemspec
65
66
  - templates/_files_by_pete.html.erb
66
67
  - templates/_files_by_pete_js.html.erb
67
68
  - templates/bootstrap.min.css
68
69
  - templates/files_by_pete.rb
69
70
  - templates/jquery-3.6.0.min.js
71
+ - templates/multiple_files_by_pete.png
70
72
  - templates/pete_file.rb
71
73
  homepage: https://rubygems.org/gems/multiple_files_by_pete
72
74
  licenses: