This file contains hidden or 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
# app/controllers/things_controller.rb | |
class ItemsController < ApplicationController | |
def create | |
thing = Thing.new(thing_params) | |
if thing.create | |
render json: thing, status: :created | |
else | |
render json: thing, status: :unprocessable_entity | |
end | |
This file contains hidden or 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
import { DirectUpload } from 'activestorage'; // https://www.npmjs.com/package/@rails/activestorage | |
createThing = (name, the_attachment) => { // name is a string, the_attachment is a File object | |
const upload = new DirectUpload( | |
the_attachment, | |
'/rails/active_storage/direct_uploads', // This url is exposed by default in your app | |
); | |
upload.create((error, blob) => { | |
if (error) { | |
// Something happened, handle the error |
This file contains hidden or 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
Rails.application.routes.draw do | |
scope ActiveStorage.routes_prefix do | |
get "/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob | |
get "/representations/:signed_blob_id/:variation_key/*filename" => "active_storage/representations#show", as: :rails_blob_representation | |
get "/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_service | |
put "/disk/:encoded_token" => "active_storage/disk#update", as: :update_rails_disk_service |