Files
railsgoat/app/controllers/benefit_forms_controller.rb
T
2016-04-19 08:43:18 -04:00

29 lines
667 B
Ruby

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.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.user_id)
end
end