rails which is best place to save static html files - ruby-on-rails

I have to save some html files and wanted to load them for some requirement.
Currently i am placing that files in public folder.
Also, i don't want to save it outside (amazon s3 etc) the rails application for some good reason.
Please let me know which is idea way to do such functionality in Rails.
I am using Rails 3.2.21

Actually I think /public is not a bad place for static html files. As long as you don't need any processing this should work well.
See here:
public − Like the public directory for a web server, this directory
has web files that don't change, such as JavaScript files
(public/javascripts), graphics (public/images), stylesheets
(public/stylesheets), and HTML files (public).

Related

What is the easiest way to integrate static pages into Rails project

I have a landing page that was passed to me by a designer, the Structure is like this
|_startup
|_common-files
|_css
|_fonts
|_icons
|_img
|_js
|_less
|_flat-ui
|_bootstrap
|_css
|_fonts
|_js
|_fonts
|_icons
|_img
|_js
|_less
|_ui-kit
|_static
|_css
|_less
index.html
I didn't type the whole structure, but the idea is, it's quite a bit of directory, and it might be tough to separate it into javascript, css, image assets, and fonts(I am not sure where fonts go). My thoughts are, should I just have a subdomain and put this about page? I do want to integrate the page into my rails project. My question is, is there an easy way to integrate an independent page into my rails project?
From the book Learn Ruby on Rails:
A Rails application can deliver static web pages just like an ordinary
web server. The pages are delivered fast and no Ruby code is required.
The Rails application server looks for any pages in the public folder
by default.
So you can drop the directory into your application public/ folder.

Assets vs Public for static videos

I have a static video in my rails application. I have two copies of it: one stored in assets/videos and one stored in public. For some reason the video stored in the assets folder loads much slower than the video stored in the public folder.
Does anyone know why?
What is the best practice? Is it bad practice to put it in public?
Does anyone know why?
Because public folder is the first place which serves incoming request. If the folder/file doesn't found in that folder, it will be forwarded to rails.
What is the best practice? Is it bad practice to put it in public?
it depends. If you want to use rails features like accessing videos folder with assets_path or may be like converting videos from one format to two with some rails script or you want restrict videos to some countries or people/user then you should put NOT put in public folder.
That's all.
The assets directory is only needed if you want to take advantage of
the asset pipeline. The asset pipeline handles things from
compressing and compiling .coffee and .less or sass files to
compressing your js and css into one file so your webserver only has
to serve one file for each.
When you compile your assets with the "rake task bundle exec rake assets:precompile" they are moved to your public directory anyhow
Check this comment https://stackoverflow.com/a/8581316/1231365
So it's better to keep your videos in the public folder.

serving large media files from the assets folder in rails

I want to put some rather large sound files into my assets folder in rails.
/app/assets/sounds
--- file1.wav
----file2.wav
when calling them thru the following URL
http://localhost:3000/assets/file1.wav
Rails (3.2.x) the file will be "served" (somehow) but I can never play it in the browser.
If however I put those files into the public folder they will be served and can be played.
I assume this is related to the fact that the public folder isn't touched by rails but is served by rack (afaik). I found a solution to use send_file but is this really needed?

Should I disable mod_rails for images and stylesheets directories?

I had a rare error in my Rails application. A CSS file was referring to non existing image files. And missing PNG file was somehow mapped to a controller action. Fortunately the action wasn't changing DB. This seems to be not OK that missing PNG can trigger controller action.
So should I disable mod_rails for static asset directories? However I've never heard this is required for Rails apps.
It is definitely a good idea, since if you allow any kind of image upload the target destination is usually the asset directory. Normally the user can quite easily upload a php or ruby file instead, so disabling all mod_evil_script for these directories is a good idea in general.
You should be serving static assets directly via Apache anyway, because it's faster. Let Rails do what it's designed to do which is handle dynamic requests.

Directory to store cached files in Rails?

I am generating some large files in my Rails application. Fortunately, they only need to be generated once. I would like to save these files to disk so that I don't have to generate them again.
Which directory in my Rails application is the most appropriate place to put application generated files?
Thanks!
If security of the files is not an issue you can put them in a subdirectory of public (for example, public/assets) which in your deploy script is symlinked to a directory in shared/public so that when you redeploy the files are retained.
If security is an issue, the solution is similar, though you would not want the directory to be web accessible. Instead you would use a controller to control access and serve up the files with send_file.

Resources