No release in over a year
An agile way to implement multiple files uploads in ruby on rails scaffold, without the need to create additional tables
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.8.0
~> 0.10.0
 Project Readme

Ruby On Rails multiple files by Pete

An agile way to implement multiple files uploads in a Ruby On Rails scaffold without the need to create additional tables

Installation

Add this line to your application's Gemfile:

gem 'multiple_files_by_pete'

And then execute:

$ bundle install

Support

Ruby On Rails: 5, 6, 7

This gem does not work with SQLite database

Usage

Let's create a example for a Place scaffold:

  1. Let's create a new rails app:
rails new myapp --database=postgresql
  1. Create the database:
bundle exec rake db:create
  1. Go to your application's directory in Terminal and run the command:
bundle exec rails g scaffold Place name:string description:text
  1. Add this line to your application's Gemfile:
gem 'multiple_files_by_pete'
  1. Go to your application's directory in Terminal and run:
bundle install
    1. Go to the application directory in Terminal and run the following command to install the necessary code and files from the gem:
bundle exec rake 'multiple_files_by_pete[place]'
  1. Add jQuery to your layout file:
<script src='/multiple_files_by_pete/jquery-3.6.0.min.js'></script>
  1. Add bootstrap.min.css to your layout file:
<link rel="stylesheet" href="/multiple_files_by_pete/bootstrap.min.css">
  1. 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
@files = PeteFile.get_object_files(@place)
  1. 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:
<%= render partial: 'shared/files_by_pete', locals: {model: @place, files: @files, section: 'legal_files' ,label: 'Upload legal files'}  %>

<%= render partial: 'shared/files_by_pete', locals: {model: @place, files: @files, section: 'extra_files' ,label: 'Upload extra files'}  %>
  1. 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:
<%= render 'shared/files_by_pete_js', model: @place, size_limit: 50%>

Video Tutorial

Watch this video to see how it works

IMAGE ALT TEXT HERE

Contributing

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.

Code of Conduct

Everyone interacting in the MultipleFilesByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.