Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last changes and "Asset Pipeline problem" fixed #34

Open
xarisd opened this issue Dec 19, 2014 · 0 comments
Open

Last changes and "Asset Pipeline problem" fixed #34

xarisd opened this issue Dec 19, 2014 · 0 comments

Comments

@xarisd
Copy link
Member

xarisd commented Dec 19, 2014

Hey guys and girls!

I've just merged the Pull Requests that have all the steps done in the last presentation plus a couple of things :

Problems running bundle exec or ./bin/rails s

Now that we have changed the Gemfile according to (newest) Heroku needs everyone MUST run

bundle install --without production

You have to run it only once as noted in the README.md (I have updated this file accordingly).

Asset Pipeline in "LOCAL production mode"

During the presentation we (I) failed to show how you run Rails in production mode with Asset Pipeline running.

Well...it was due to a childish error caused by the pressure to finish the presentation early :-)

I will try to explain it here

  • We did not have any web server (Apache/nginx) to serve our static assets.
  • Rails production environment was set NOT to serve static assets

So there was no one serving the assets.

Due to this problem we could not see any CSS file.

Heroku case

Nevertheless our Heroku deployment worked as a charm.

Why?

Because the "serve static assets" configuration is done automatically once you include rails_12factor gem so we don't have to do anything.

OK I want to run it locally

To enable this option you can simply open config/environments/production.rb in line 23 and change it to the following

config.serve_static_assets = true

BUT there is a better way:

  • We can read this option from an ENV variable (or turn it to false by default)
  • We can use a gem called figaro to set the environment variables from a file called application.yml (ignored by git) instead of the command line
  • We can make a sample file called application.example.yml (tracked by git) to hold sample key-value pairs so we don't have to remember what to put inside this configuration

AND it gets better!

Make a rake task that automatically generates a ready to use application.yml for setting the production environment in DEVELOPMENT machine.

So we can call from the command line

rake  dev:prepare:production_local

and have all the necessary configuration ready.

Then we can run Rails in production mode locally having the (Ruby) application server set to serve the static assets (CSS, JS, Images)

./bin/rails s -e production

All the above changes are merged in the PR #32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant