When user uploads files. In Rails 3.0+, these would go into public/uploads. In 3.1, should uploaded files go to app/assets/uploads? Or still in public/uploads?
It's not really an issue in our environment, since we are using S3. Just trying to understand Rails 3.1's new directory structure.
What are your thoughts?
the public directory, capistrano recommends public/system/
don't get confused by the app/assets directory, it's usually for css/js/coffeescript files, think this is the biggest change from 3.0 to 3.1
Well, the answer is simple: your users will only have access to your /public directory.
There are just some tricks to get css and js but you'll have to stick with /public for the other stuff.
Generally, I put all stuff in /public/assets
adding on to apneadiving's answer:
if you use Carrierwave , the temporary files are in your system's /tmp directory and the uploaded files are in a subdirectory underneath $RAILS_ROOT/public , e.g. $RAILS_ROOT/public/uploads/YOUR-MODEL/...
In Rails 3.1 the 'assets' directory is meant for the JavaScript and CSS files so that sprockets can pick them up there and so that they are not accessible directly via the "public" directory...
see: assets/javascripts/application.js and assets/stylesheets/application.css files
see: http://railscasts.com/episodes/265-rails-3-1-overview
The app/assets directory is for CoffeeScript files (also not publicly accessible, so not a place to put uploads)
Putting uploaded files in the filesystem only works if you have one file server or a network mapped storage... I usually just put the files in the database itself.
But as vrsmn said, don't use assets for this, assets pipeline is for streamlining the css/js/application images.
Related
I have several sounds files that are located in public/assets/sounds.
Locally everything works fine, but when I deploy via Capistrano to my ec2 instance, none of those assets make it to the server. I added 'public/assets/sounds' to :linked_dirs in deploy.rb. A directory shows up at 'public/assets/sounds' but none of the mp3s are there. Do I need to manually add all files via :linked_files?
I have it working by just loading the files into the shared/public/assets/sounds directory via ftp, but that doesn't seem like the best use of the Capistrano. I'm also new to Capistrano and could be totally wrong :p
The public/assets directory is reserved for the Rails asset pipeline. You should not place any files there. Here's what I would do:
Remove public/assets/sounds from :linked_dirs.
Choose a different place for the mp3 files, like public/sounds.
Do not add this directory to :linked_dirs.
I have a PEM file that should be stored somewhere in my Ruby on Rails web app, and be referenced from the production.rb config file with the path, as per below.
APNS.pem = '/path/to/pem/file'
I want to keep this file private, so storing it in the assets folder is not a good idea. Where can I safely store it and what would be the path like?
You can place it anywhere in your app outside of public and assets and it will be inaccessable from the web. Placing it in config/ is a common option.
To build a path to the file, you would use Rails.root.join('config/file.pem')
I upgraded an old Rails 2.3 application to version 3.2, and am in the process of switching my javascripts to use the Asset Pipeline.
Everything under app/assets is being included just fine. I had to create the directories under vendor by hand, but nothing is being picked up there. So I printed out the contents of Rails.application.config.assets.paths in the console, and sure enough the assets under vendor and lib are not in the path.
But I looked in another one of my existing Rails 3.2 applications, and sure enough vendor and lib are picked up fine.
But I grepped the config directory of that application for the word vendor and come up with nothing. So apparently lib and vendor get included implicitly somehow. I can't figure out how to add these.
I just needed to restart the application, and those directories were picked up.
I've got a Rails site with a Jekyll blog incorporated, using the Bloggy gem.
I'd like a similar look for the main site and the blog, so I want to use the css in app/assets/stylesheets, but those files are in css.scss format. Jekyll (in a Bloggy setup) looks for css in config/jekyll/css, and seems to only want .css files; symlinking the Rails css directory into the Jekyll hierarchy doesn't seem to to work.
Is there a way to take advantage of the asset pipeline so that when I run jekyll:build, SCSS files from the Rails app are made into CSS files, placed in the appropriate jekyll directory, and bundled with the latest Jekyll build as it's placed into the /public/blog folder?
Thanks!
Ended up getting through this by:
Using the jekyll-sass gem to allow automatic transformation of the Rails app's .css.scss into .css.css files. By symlinking the Rails app/assets/stylesheets directory into Bloggy's config/jekyll/css, this put files with the right content but wrong extensions in the correct place.
Writing a rake task to make the .css.css files into .css files.
desc 'Make .css.css files into .css files'
task :css_css do
Dir.glob('public/blog/css/*.css.css').each do |file|
puts `mv #{file} #{file.gsub(/\.css\.css$/, '.css')}`
end
end
Not the prettiest solution, but it works.
#Matthew.. You have a nice solution.. For this part I did some stuffs manually. Like I added config/jekyll/css files as .css extension rather than .css.scss so when we run "rake generate" for bloggy the right format files are created on the folder public/blog/ rather css.scss.
I have made the changes in my bloggy portfolio theme project repository. If you are planning to use my version of code, I have did some changes like added robots.txt, sitemap, and integrated bootstrap to the project. I have also removed all database connections from the rails project since it was showing errors while deploying into heroku.
I wrote a function in Ruby on Rails for uploading a PDF.
The file is uploaded to a folder in public, but every time I deploy to staging or production, the folder on the server seems to become empty.
How to choose the right folder?
In my opinion the easiest way will be to use paperclip
https://github.com/thoughtbot/paperclip
You can easily set folder somewhere like /home/rails/attachments
In documentation for paperclip you have
The files that are assigned as attachments are, by default, placed in the directory specified by the :path option to has_attached_file. By default, this location is :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename. This location was chosen because on standard Capistrano deployments, the public/system directory is symlinked to the app's shared directory, meaning it will survive between deployments. For example, using that :path, you may have a file at /data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png