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 +4 -4
- data/README.md +84 -11
- data/lib/multiple_files_by_pete/version.rb +1 -1
- data/lib/tasks/multiple_files_by_pete.rake +13 -8
- data/multiple_files_by_pete-0.2.1.gem +0 -0
- data/templates/_files_by_pete.html.erb +24 -25
- data/templates/_files_by_pete_js.html.erb +1 -1
- data/templates/multiple_files_by_pete.png +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58e95ca2a7501fe64ea531413ba520debf93db0a5093a2f24ce3999f9cb538e1
|
4
|
+
data.tar.gz: aa63218454cdb700efb0eeffe37a7bcc90d365e72c3a89c747464a31c38ed012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7d3c800a22d907f8161e44d3c7437ca4372ffe268a719e6733959689c9cfe685bc218556b89f5cfafb3191b89b7e0ba010bfd67ed4e5ab6b9ff904541833099
|
7
|
+
data.tar.gz: 5ebfc7c05c4c47f0ab561c32c891eacc9bf783b3f1b28711f9c6b6fe10229748e69d53d9ef29f795851d88b3dd87260c6499054d66e5ec12f2ff8036efdf9453
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# Ruby On Rails multiple files by Pete
|
2
2
|
|
3
|
-
|
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
|
-
|
18
|
+
## Support
|
20
19
|
|
21
|
-
|
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
|
-
|
100
|
+
Watch this video to see how it works
|
26
101
|
|
27
|
-
|
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/
|
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/
|
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,12 +1,13 @@
|
|
1
1
|
require_relative '../peterconsuegra_recipes'
|
2
|
+
require 'colorize'
|
2
3
|
|
3
|
-
#bundle exec rake 'multiple_files_by_pete[
|
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
|
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
|
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
|
-
|
9
|
+
%>
|
15
10
|
|
16
|
-
<
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
</form>
|
29
|
-
|
30
|
-
</div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
</div>
|
31
30
|
|
32
31
|
<%end%>
|
Binary file
|
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.
|
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-
|
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:
|