How do I serve nested static content on Heroku? - ruby-on-rails

I have a rails application with static content in the public directory (e.g. public/index.html) and additional static content in nested subdirectories (e.g. public/one/two/index.html).
All the static content is served correctly if I run it locally via script/server but when I upload it to Heroku the top-level page loads correctly but the nested content returns a 404.
I've found a number of resources (for example this question) which discuss static content in rails but they all seem to assume a fairly simple structure with a single directory containing all the files.
Is there any way I can fix this?

If you have a very simple web application (with mostly static content, say) then using Sinatra on Heroku is much simpler to set up and prevents this type of problem.

You can serve up static content on Heroku without writing any "code" at all... you just need to tell the "Rack" middleware where the content is (as detailed in this help article):
http://devcenter.heroku.com/articles/static-sites-on-heroku

Related

Difference between Public and View of ruby on rails

What are the exact difference between the functionalities of app/View part and Public part of ruby on rails.
It seems that similar type of assets like js functions etc are defined in both.
what are the reasons behind defining the same things twice
In the public directory, Rails stores only static assets, i.e. files which are sent to the client as is without any further processing. These files can be generated using the assets pipeline (e.g. javascript assets or CSS files). However, they are only generated once (typically) during deployment.
The views however are the templates used by rails to generate the response to a dynamic request. Thus, if a user requests a certain (dynamic) action from your application, your controller decides which view to render. Its output is then sent to the browser. The view can thus be highly dynamic so that their output can change for each request.

rails which is best place to save static html files

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).

Ruby on Rails with Github Pages

I am attempting to host a project using Github pages. As I understand it, Ruby on Rails cannot be run on GH-Pages, with the exception of using Jekyll. My project is not a blog, and therefor Jekyll seems like overkill. Is there any other way to deploy to GH-Pages? Is there another way to generate a static site from my Ruby on Rails app that would allow for easier deployment?
Thanks for any and all input.
I'm afraid not. Rails is a dynamic system, meaning that the pages are generated from templates combined with data. GH-pages only servers static HTML, so even if you put static content into Rails, you would not be able to run the scripts that serve it.
Use Jekyll or Middleman to make a static site. If you really need Rails, use Heroku's free plan.
You could use actionpack-page_caching to generate page-level caches in the public folder of your Rails application, then add those generated pages to your GitHub Pages repository.
However, this entirely defeats the purpose of using something like Rails. Why don't you just create static pages directly and upload those to your GitHub Pages repo?

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.

Compile Rails application to static site

I want to know if there is a way (or a gem) that can compile me a Rails application into a static web site; I have some files that need to only be compiled once (i.e. they have no dynamic content but they need to be parsed at least once). I can't seem to find any way to do that so I have a feeling that it might not even be possible.
I don't believe there's a way to do that with an entire Rails app. That's more the territory of https://github.com/mojombo/jekyll or https://github.com/imathis/octopress. If it's only a few pages you can use caches_page :page1, :page2, ... in your controllers. That will write the fully-rendered page to public/ so that it can be served directly by Nginx/Apache on subsequent requests.
Edit In Rails 4 you'll need to use the actionpack-page_caching gem.

Resources