Compare commits
1 Commits
17ffd2fea7
...
5b60424532
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5b60424532 |
@ -1,5 +1,3 @@
|
|||||||
require 'csv'
|
|
||||||
|
|
||||||
class GuestsController < ApplicationController
|
class GuestsController < ApplicationController
|
||||||
before_action :set_guest, only: %i[show edit update destroy]
|
before_action :set_guest, only: %i[show edit update destroy]
|
||||||
|
|
||||||
@ -60,20 +58,6 @@ class GuestsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def import
|
|
||||||
csv = CSV.parse(params[:file].read, headers: true)
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
csv.each do |row|
|
|
||||||
guest = Guest.create!(first_name: row['name'])
|
|
||||||
|
|
||||||
guest.affinity_group_list.add(row['affinity_group'])
|
|
||||||
guest.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect_to guests_url
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
@ -29,9 +29,3 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= link_to "New guest", new_guest_path %>
|
<%= link_to "New guest", new_guest_path %>
|
||||||
|
|
||||||
<%= form_with url: import_guests_path, method: :post do |form| %>
|
|
||||||
<%= form.label :file %>
|
|
||||||
<%= form.file_field :file %>
|
|
||||||
<%= form.submit "Import" %>
|
|
||||||
<% end %>
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :guests do
|
resources :guests
|
||||||
post :import, on: :collection
|
|
||||||
end
|
|
||||||
resources :expenses
|
resources :expenses
|
||||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
|
|||||||
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
||||||
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 8fd0b7c (Modify seeds file to make sure every guest is part of a group)
|
||||||
samples = {
|
samples = {
|
||||||
close_family: 10,
|
close_family: 10,
|
||||||
family_1_group_a: 5,
|
family_1_group_a: 5,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user