The task: Serve the files located in a local folder on the server to clients over http/80.
In the end, I plan to emulate the folder on the client but that doesn't concern my question.
So, there is an existing Rails app (rest based/xml) on that server that the clients would use in conjunction with these files.
I don't need any logic to be done on the files either on upload or download so I ask myself:
Do I need to involve my Rails app in serving these files?
Shouldn't the webserver solely handle the link between the local files and the clients?
Would this new Rails Metal or Rack integration be part of the solution? (not familiar with either)
I guess the important thing here is http over port 80.
Thanks for any pointers or advice on the matter,
cheers, Max
I know that with the good time investment I could look all this up for a couple of hours and figure it out but I am very very busy saves me alot of time.
Apache? Just add another <Directory> section to your configuration for the Rails app:
Alias /static-files /path/to/the/static-files
<Directory /path/to/the/static-files>
Order allow, deny
Allow from all
# whatever else you need, Options, AllowOverride, etc.
</Directory>
Put the files in a subdirectory of the "public" directory - as with stylesheets and javascripts
you can use X-Sendfile if you are using Apache or Lighty (see this blog post). Nginx supports X-Accel-Redirect. Both of these approaches will let your web server directly send the file without involving your rails app.
Related
I want to add frameworks like AngularJS, Bootstrap and polymer JS into my rails app. Problem with the gems is they are unstable with new versions and they even stop developing gems(which leads to failing of one gem which depends on another)
So I just want to add those frameworks directly into the application root html file via CDN(offered by the vendor). Is that a good practice? Will it cause any future problems in production environment?
Yes, if you are using reliable CDN's (and those offered my vendors can be treat as one) it may even bring you some improvements in the production enviromnent, e.g.:
those assets will be often already cached on your user's machines
it circumvents browsers limit the number of concurrent connections from the same domain (as your app)
On the flip side, on your dev enviromnent you'll have to wait a liiitle bit more for the website to load those assets comparing it to loading them from localhost ;)
if you dont use CDN,you have much control over the assets ,as they might change/update or sometimes the url can be down :( in worst case scenario..so i suggest using local assets if there is large dependency and for small dependency ...you may use cdn. :)
use this to set up polymer js onlocal.
I have a front-end single page app written in AngularJS, and I want to use Rails to build a back-end API.
I wonder if it is OK to put all front-end files in Rails' public folder, and mount all Rails' API routes on api/xxxx. In this way, I can save developers' efforts so they don't need to run two server when developing (front-end server and back-end rails' server). Also, I don't need to care about Rails' assets pipeline. I can use totally pure front-end solution to optimize fron-tend application. All I need to do is just put them into one single applications.
Is there any drawback of such design?
Yes, that perfectly fine. In fact, this is what rake assets:precompile does.
I am trying to create a rails app that will run on my main domain, which will have a bunch of subdomains that will all be separate static websites.
I want the files for these static sites to each be in their own folder on an S3 bucket I created. So, going to mysite.example.com you would see the index.html file in the mysite folder on S3. The user's browser would also have to be able to pull any of the CSS and images referenced in index.html
Is there any way to do this? If possible I would like to do this off of Heroku, but that might not be feasible.
The right_aws gem might be exactly what you're looking for; it claims to offer S3 and EC2 support, among other services.
I'm using jammit to embed data-uri's in my rails app. This is not a jammit or rails specific question though.
For each css file generated, jammit creates two versions i.e.:
style-datauri.css (75KB)
style-datauri.css.gz (40KB)
I know that everything is working because my production app is serving data-uri's to firefox and chrome, and whilst I don't have access to IE, screenshots from browsershots suggest that all is well.
Q1: How can I test that the gzipped version of my stylesheet is the one which is being served to the browser? I care because it's a significantly smaller file.
(I guess I could change the font-size in the non-gzipped css file and see what happens but I'm hoping there's a simpler way - perhaps using curl or something)
Q2: The app is hosted on heroku and I know from their docs that they gzip everything for you, but I'm also told that jammit uses the highest compression level and that heroku don't. Will my file be gzipped twice then? Once by jammit, and then once more by nginx?
Q1
You can inspect the HTTP headers to guess what's happening; nginx can be told to serve gzipped version of your css or to create a zipped version on the fly, but I am not sure you can easly say what is being server from the client point of view.
Q2
Heroku sports a powerful caching / optimizing frontend system powered by nginx and Varnish; they will be happy to explain you how to make your app consuming less resources.
BONUS
Loading the home page of your web app my browser downloads over 1MB of data; to make it snappier you can lazy load images via Javascript.
I have a Rails app and I want to add a blog feature; my idea is to use Jekyll which is a great blog tool, I just need to figure out if it's possible to use http://my.app.com/blog as a url (knowing that Jekyll will run its own server process with its own url).
Does anybody know of a way to accomplish this? It'd be great to be able to do so. Best regards!
... just need to figure out if it's possible to use http://my.app.com/blog
as a url (knowing that Jekyll will run its own server process with its own url).
While jekyll's web server works, it will be probably easier, simpler and safer to use your rails app's webserver for serving all pages.
The simplest way of doing what you want is hooking a jekyll invocation to your server's git repository, so jekyll's static content is added automatically to your rails app's public/blog/ directory every time there is a push.
Create a symbolink link called public/blog inside your app's public folder. Make it point to the generated _site folder of your jekyll repository.
On the git repository that controls the contents of the jekyll blog, add a post-receive hook that does the following:
#!/bin/sh
rm -rf _site
jekyll
Those are the basic steps. You might have to configure the read permissions properly, ignore the /blog/ link if you are using an SCM (like you should) and automate the link creation if you are using Capistrano or Vlad for deploying.
There are other alternatives, like using a real folder instead of a symbolic link and having jekyll generate stuff directly there, but I feel the one I'm presenting is the cleanest.
Would you be using nginx to reverse-proxy the Rails app? If so, you should be able to just carve out an exception so /blog is served directly by nginx instead of forwarded to Rails.
Check out this gem: https://github.com/zbruhnke/bloggy
And this blog post about it: https://blog.engineyard.com/2012/introducing-bloggy-a-simple-way-to-add-a-jekyll-blog-to-any-rails-application
I had the same problem a few weeks ago. If you really have to use Jekyll, I think the best solution is to use the already mentioned Bloggy gem.
However, I wasn't satisfied with this solution, because you still have to duplicate or synchronize a lot of things like templates, routes, stylesheets, and so on. So I decided to implement my own simple Jekyll-like blog functionality in Rails.
You can find my article describing the implementation here: Create a simple Jekyll-like blog in your Rails 4 app.