Created
September 22, 2019 18:24
-
-
Save staycreativedesign/0283912c26f3d3cb17ad9b2ddac9fc21 to your computer and use it in GitHub Desktop.
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
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 |
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
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