I'm currently building a very simple API in rails. All I need to do is upload text and images on heroku, store that uploaded data on S3 in JSON (so I'm guessing rendering it as JSON when saving?) and pull that data into my frontend via AJAX. I'm using the paperclip and 'aws-sdk' gem and I'm succesfully saving images into my S3 bucket, I just need to serialize it into JSON.
In my controller I have:
def create
@project = Project.new(project_params)
render :json => @project
@project.save
redirect_to @project
end
My model:
class Project < ActiveRecord::Base
has_attached_file :photo, :styles => { :small => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
end
and In my production environment I have:
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
At present this is just saving the images into subfolders in my bucket, I would like to save this into one folder and render it is as JSON. I'm new to rails so apologies if I have missed anything out. Thanks