-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
668 additions
and
3 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 |
---|---|---|
|
@@ -19,4 +19,5 @@ | |
.byebug_history | ||
/public/packs | ||
/public/packs-test | ||
/public/uploads | ||
/node_modules |
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 |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
//= require popper | ||
//= require bootstrap | ||
//= require turbolinks | ||
//= require trix | ||
//= require_tree . |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Turn off the default Trix captions | ||
Trix.config.attachments.preview.caption = { | ||
name: false, | ||
size: false | ||
}; | ||
|
||
function uploadAttachment(attachment) { | ||
// Create our form data to submit | ||
var file = attachment.file; | ||
var form = new FormData; | ||
form.append("Content-Type", file.type); | ||
form.append("photo[image]", file); | ||
|
||
// Create our XHR request | ||
var xhr = new XMLHttpRequest; | ||
xhr.open("POST", "/photos.json", true); | ||
xhr.setRequestHeader("X-CSRF-Token", Rails.csrfToken()); | ||
|
||
// Report file uploads back to Trix | ||
xhr.upload.onprogress = function(event) { | ||
var progress = event.loaded / event.total * 100; | ||
attachment.setUploadProgress(progress); | ||
} | ||
|
||
// Tell Trix what url and href to use on successful upload | ||
xhr.onload = function() { | ||
if (xhr.status === 201) { | ||
var data = JSON.parse(xhr.responseText); | ||
return attachment.setAttributes({ | ||
url: data.image_url, | ||
href: data.url | ||
}) | ||
} | ||
} | ||
|
||
return xhr.send(form); | ||
} | ||
|
||
// Listen for the Trix attachment event to trigger upload | ||
document.addEventListener("trix-attachment-add", function(event) { | ||
var attachment = event.attachment; | ||
if (attachment.file) { | ||
return uploadAttachment(attachment); | ||
} | ||
}); |
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 Photos 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Posts 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
margin: 33px; | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { | ||
color: #000; | ||
|
||
&:visited { | ||
color: #666; | ||
} | ||
|
||
&:hover { | ||
color: #fff; | ||
background-color: #000; | ||
} | ||
} | ||
|
||
th { | ||
padding-bottom: 5px; | ||
} | ||
|
||
td { | ||
padding: 0 5px 7px; | ||
} | ||
|
||
div { | ||
&.field, &.actions { | ||
margin-bottom: 10px; | ||
} | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px 7px 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
|
||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px -7px 0; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
} | ||
|
||
label { | ||
display: block; | ||
} |
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,74 @@ | ||
class PhotosController < ApplicationController | ||
before_action :set_photo, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /photos | ||
# GET /photos.json | ||
def index | ||
@photos = Photo.all | ||
end | ||
|
||
# GET /photos/1 | ||
# GET /photos/1.json | ||
def show | ||
end | ||
|
||
# GET /photos/new | ||
def new | ||
@photo = Photo.new | ||
end | ||
|
||
# GET /photos/1/edit | ||
def edit | ||
end | ||
|
||
# POST /photos | ||
# POST /photos.json | ||
def create | ||
@photo = Photo.new(photo_params) | ||
|
||
respond_to do |format| | ||
if @photo.save | ||
format.html { redirect_to @photo, notice: 'Photo was successfully created.' } | ||
format.json { render :show, status: :created, location: @photo } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @photo.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /photos/1 | ||
# PATCH/PUT /photos/1.json | ||
def update | ||
respond_to do |format| | ||
if @photo.update(photo_params) | ||
format.html { redirect_to @photo, notice: 'Photo was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @photo } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @photo.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /photos/1 | ||
# DELETE /photos/1.json | ||
def destroy | ||
@photo.destroy | ||
respond_to do |format| | ||
format.html { redirect_to photos_url, notice: 'Photo was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_photo | ||
@photo = Photo.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def photo_params | ||
params.require(:photo).permit(:image) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class PostsController < ApplicationController | ||
before_action :set_post, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /posts | ||
# GET /posts.json | ||
def index | ||
@posts = Post.all | ||
end | ||
|
||
# GET /posts/1 | ||
# GET /posts/1.json | ||
def show | ||
end | ||
|
||
# GET /posts/new | ||
def new | ||
@post = Post.new | ||
end | ||
|
||
# GET /posts/1/edit | ||
def edit | ||
end | ||
|
||
# POST /posts | ||
# POST /posts.json | ||
def create | ||
@post = Post.new(post_params) | ||
|
||
respond_to do |format| | ||
if @post.save | ||
format.html { redirect_to @post, notice: 'Post was successfully created.' } | ||
format.json { render :show, status: :created, location: @post } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @post.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /posts/1 | ||
# PATCH/PUT /posts/1.json | ||
def update | ||
respond_to do |format| | ||
if @post.update(post_params) | ||
format.html { redirect_to @post, notice: 'Post was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @post } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @post.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /posts/1 | ||
# DELETE /posts/1.json | ||
def destroy | ||
@post.destroy | ||
respond_to do |format| | ||
format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_post | ||
@post = Post.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def post_params | ||
params.require(:post).permit(:title, :body) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PhotosHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PostsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ImageUploader < Shrine | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Photo < ApplicationRecord | ||
include ImageUploader[:image] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Post < ApplicationRecord | ||
end |
Oops, something went wrong.