Skip to content

Instantly share code, notes, and snippets.

@alnutile
Last active December 20, 2015 22:29
Show Gist options
  • Save alnutile/6205464 to your computer and use it in GitHub Desktop.
Save alnutile/6205464 to your computer and use it in GitHub Desktop.
Setting up s3, paperclip and ckeditor with a s3-us-west-2.amazonaws.com type domain. From here all uploads via ckeditor or a paperclip manage file just worked. Also cap deploy so this symlink is in place
# this post helped here
# http://stackoverflow.com/questions/705054/where-do-you-put-your-app-config-files-when-deploying-rails-with-capistrano-and
# get your file to the server under shared
# then update cap to handle the symlink update
namespace :deploy do
task :start do ; end
task :stop do ; end
# this task
task :symlink_shared do
run "ln -s #{shared_path}/s3.yml #{release_path}/config/"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
# this line triggers it
before "deploy:restart", "deploy:symlink_shared"
# app/models/ckeditor comes with a model as well
# also the file attachment_files.rb
# as above just make sure you did not code in here a url or path
class Ckeditor::AttachmentFile < Ckeditor::Asset
has_attached_file :data,
:path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
# same with development.rb
# environment/production.rb
config.paperclip_defaults = {
:storage => :s3,
:url => ':s3_alias_url',
:path => "/:class/:id/:style/:clean_filename",
:s3_host_alias => 's3-us-west-2.amazonaws.com/nutilesblog',
:s3_credentials => "#{Rails.root}/config/s3.yml"
}
# app/models/project.rb
# make sure you are not overriding paths or url settings here
has_attached_file :photo,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:styles => {
:thumb => "100x100",
:medium => "200x200",
:large => "600x400"
}
# this helped to hide the secret settings from git
# but at the same time not set them in the envirnment variables of the shell.
# config/s3.yml
development: &DEFAULTS
bucket: nutilesblog
access_key_id: 'access key'
secret_access_key: 'secret key'
test:
<<: *DEFAULTS
bucket: nutilesblog
production:
<<: *DEFAULTS
bucket: nutilesblog
staging:
<<: *DEFAULTS
bucket: nutilesblog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment