Files
railsgoat/app/controllers/benefit_forms_controller.rb
T
2017-12-12 15:25:37 -06:00

30 lines
678 B
Ruby

# frozen_string_literal: true
class BenefitFormsController < ApplicationController
def index
@benefits = Benefits.new
end
def download
begin
path = params[:name]
file = params[:type].constantize.new(path)
send_file file, disposition: "attachment"
rescue
redirect_to user_benefit_forms_path(user_id: current_user.id)
end
end
def upload
file = params[:benefits][:upload]
if file
flash[:success] = "File Successfully Uploaded!"
Benefits.save(file, params[:benefits][:backup])
else
flash[:error] = "Something went wrong"
end
redirect_to user_benefit_forms_path(user_id: current_user.id)
end
end