Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created September 22, 2019 18:24
Show Gist options
  • Save staycreativedesign/0283912c26f3d3cb17ad9b2ddac9fc21 to your computer and use it in GitHub Desktop.
Save staycreativedesign/0283912c26f3d3cb17ad9b2ddac9fc21 to your computer and use it in GitHub Desktop.
def create
blob = ActiveStorage::Blob.create_after_upload!(
io: params[:file][0],
filename: params[:file][0].original_filename,
content_type: params[:file][0].content_type
)
respond_to do |format|
format.json do
render json: {
"file": {
"thumb": "",
"url": url_for(blob),
"id": blob.id,
"title": blob.filename
}
}.to_json
end
end
end
def upload_images
@post.images.attach(params[:file])
respond_to do |format|
format.json do
render json: {
"file": {
"thumb": "",
"url": url_for(@post.images.last),
"id": @post.images.last.id,
"title": @post.images.last.id
}
}.to_json
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment