-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from metacorn/Part_7_ActiveStorage
Part 7. ActiveStorage.
- Loading branch information
Showing
44 changed files
with
496 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ | |
|
||
# Ignore database settings | ||
/config/database.yml | ||
|
||
# Ignore secret configs | ||
/config/secrets/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Files controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class FilesController < ApplicationController | ||
def destroy | ||
@file = ActiveStorage::Attachment.find(params[:id]) | ||
return head :forbidden unless @file.record_type.in?(%w[Question Answer]) | ||
@file.purge if current_user&.owner?(@file.record) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FilesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
div id="answer_#{answer.id}" | ||
div id="answer_#{answer.id}" class="mb-3" | ||
- if answer.persisted? | ||
|
||
- if answer.best? | ||
div id="best-answer" | ||
h4 The best answer | ||
p= answer.body | ||
p= render(partial: 'shared/answer_links', locals: { answer: answer }) | ||
h5 The best answer | ||
|
||
p class="mb-1"= answer.body | ||
|
||
- if answer.files.attached? | ||
div class="answer-files mb-1" | ||
- answer.files.each do |file| | ||
p.mb-0 | ||
= link_to file.filename.to_s, url_for(file) | ||
=< link_to('Delete file', file_path(file), method: :delete, remote: true) if current_user&.owner?(answer) | ||
|
||
p class="mb-1"= render(partial: 'shared/answer_links', locals: { answer: answer }) | ||
|
||
= form_with model: answer, class: 'hidden', html: { id: "edit-answer-#{answer.id}" } do |f| | ||
= f.label :body, 'Your answer' | ||
= f.text_area :body | ||
= f.submit 'Update' | ||
div= f.label :body, 'Your answer', class: "mb-0" | ||
div= f.text_area :body, cols: 32, rows: 3 | ||
div= f.label :files, 'Files', class: "mb-0" | ||
div= f.file_field :files, multiple: true, direct_upload: true, class: "mb-3" | ||
div= f.submit 'Update' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% if @file.record_type == "Question" %> | ||
<% @question = @file.record %> | ||
$("#question_" + <%= @question.id %>).replaceWith('<%= j render 'questions/question_for_show', resource: @question %>') | ||
<% elsif @file.record_type == "Answer" %> | ||
<% @answer = @file.record %> | ||
$("#answer_" + <%= @answer.id %>).replaceWith('<%= j render 'answers/answer', answer: @answer %>') | ||
<% end %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
doctype html | ||
html | ||
head | ||
title QnA | ||
= csrf_meta_tags | ||
= csp_meta_tag | ||
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' | ||
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' | ||
body | ||
div class="navbar navbar-expand-sm navbar-light bg-light" | ||
= render 'shared/user_nav' | ||
div class="container" | ||
div class="mt-2 row justify-content-center" | ||
div class="col col-sm-6" | ||
- if flash[:notice].present? | ||
p.notice= notice | ||
- if flash[:alert].present? | ||
p.alert= alert | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
p= question.title | ||
p | ||
= link_to question.title, question_path(question) |
Oops, something went wrong.