Skip to content

Commit

Permalink
got homeschool file upload working on backend and looking kind of ok …
Browse files Browse the repository at this point in the history
…on frontend
  • Loading branch information
ArushC committed Apr 19, 2024
1 parent 13dde00 commit 3877239
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def edit
@readonly = !is_admin?
end

def remove_file
file_attachment = @teacher.files.find(params[:file_id])
if file_attachment.purge
flash[:notice] = "File removed successfully"
else
flash[:alert] = "Failed to remove file"
end
redirect_to teacher_path(@teacher)
end

def update
load_school
ordered_schools
Expand Down
2 changes: 1 addition & 1 deletion app/views/teachers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ status ONLY IF the person viewing this page is an admin. %>
<div class='form-group row' id = 'upload_file_field'>
<div class='col-12'>
<%= f.label :files, "Upload supporting files: " %>
<%= f.file_field :files, multiple: true %>
<%= f.file_field :files, multiple: true, direct_upload: true %>
</div>
</div>

Expand Down
20 changes: 20 additions & 0 deletions app/views/teachers/_teacher_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@
<%= teacher.display_application_status %>
</div>
</div>
<% if teacher.files.attached? %>
<div class="row mb-4">
<div class="col-sm-4 font-weight-bold">Uploaded Files:</div>
<div class="col-sm-8">
<% if @teacher.files.attached? %>
<% @teacher.files.each do |file| %>
<div class='form-group row'>
<%= link_to file.filename.to_s, rails_blob_path(file), target: "_blank", class: "box-link" %>

<div class='col-6'>
<%= button_to "❌", remove_file_teacher_path(@teacher, file_id: file.id), method: :delete, data: { confirm: "Are you sure you want to remove this file?" }, style: "width: 40px;", class: "box-link" %>
</div>
</div>
<% end %>
<% else %>
<p>No files attached yet.</p>
<% end %>
</div>
</div>
<% end %>
<div class="row mb-4">
<div class="col-sm-4 font-weight-bold">Personal or Course Website:</div>
<div class="col-sm-8">
Expand Down
14 changes: 14 additions & 0 deletions app/views/teachers/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<%= provide(:h1, "#{@status} View #{@teacher.full_name}") %>

<head>
<style>
/* Define the style for the box around the file upload link */
.box-link {
display: inline-block; /* Allow the element to take width and height properties */
padding: 5px 10px; /* Add some padding inside the box */
height: 40px;
border: 1px solid #ccc; /* Add a border around the box */
border-radius: 5px; /* Add rounded corners (optional) */
background-color: #f9f9f9; /* Add a light background color (optional) */
}
</style>
</head>

<%= render 'teacher_info', teacher: @teacher %>

<hr>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@

# Store files locally
# config.active_storage.service = :amazon
# config.active_storage.service = :local
config.active_storage.service = :local
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
post :validate
post :deny
post :request_info
delete 'remove_file', to: 'teachers#remove_file'
end
collection { post :import }
end
Expand Down

0 comments on commit 3877239

Please sign in to comment.