Forum: Ruby on Rails Understating how assets in Rails 4 work in production

A00673345921ae8c2e5570d1bd48b2e2?d=identicon&s=25 J. mp (lerias)
on 2013-07-21 02:31
(Received via mailing list)
When I run

rake assets:precompile

The compiled assets are written to pubic/assets:

I, [2013-07-21T02:16:00.987988 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png
I, [2013-07-21T02:16:01.037698 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png
I, [2013-07-21T02:16:01.053630 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-01-b85e542137a02bedd6c30dede873ef1e.jpg
I, [2013-07-21T02:16:01.066371 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-02-e5106e911d8a0289bfaf2ac64308a640.jpg
I, [2013-07-21T02:16:01.077879 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-03-990dccbed4c70f0118b7d30d98094811.jpg
I, [2013-07-21T02:16:01.965560 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/application-98713f9763bccfd6bc05dae422d3e242.js
I, [2013-07-21T02:16:02.068469 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/application-a40c2cd9b0f20b2a7f3b62d45159fbb3.css

Then, I start the application in production, with:

RAILS_ENV=production rails s
=> Booting WEBrick=> Rails 4.0.0 application starting in production on
http://0.0.0.0:3000=> Run `rails server -h` for more startup options=>
Ctrl-C to shutdown server[2013-07-21 02:20:49] INFO  WEBrick
1.3.1[2013-07-21 02:20:49] INFO  ruby 2.0.0 (2013-06-27)
[x86_64-linux][2013-07-21 02:20:49] INFO  WEBrick::HTTPServer#start:
pid=13903 port=3000

But the rendered pages, don't look for the precompiled asses. In the
rendered templates I got:

<!DOCTYPE html><html><head>
  <title>App Home Pagetitle>

  <link data-turbolinks-track="true" href="/stylesheets/application.css"
media="all" rel="stylesheet" />
  <link href="/stylesheets/application.css" media="all" rel="stylesheet"
/>
  <link href="/stylesheets/marketing.css" media="all" rel="stylesheet"
/>
  <script src="/javascripts/application.js"></script>
  <script src="/javascripts/marketing.js"></script>
  <meta content="authenticity_token" name="csrf-param" />
  <meta content="8XQYBZWrTxmfdGvQYCK0JwQDfr2pt8si+FjW4a30SsA="
name="csrf-token" /></head><body>
</body></html>

The template is the following:

!!! 5%html
  %head
    %title App Home Page
    =yield(:head)
    = stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true
    = stylesheet_link_tag "application", params[:controller], :media =>
"all"
    = javascript_include_tag "application", params[:controller]
    = csrf_meta_tags
  %body
    =flash_messages(flash)
    = yield

My production.rb is as follows:

WebApp::Application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.assets.version = '1.0'
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new

end

What I need to configure to have stylesheet_link_tag and
javascript_include_tag pick the right assets location on production?

Thanks
F50d3b02eee623a2172b58c09fe31c2c?d=identicon&s=25 mike (Guest)
on 2013-07-21 18:24
(Received via mailing list)
On Saturday, July 20, 2013 8:29:42 PM UTC-4, Joo Pereira wrote:
> I, [2013-07-21T02:16:01.066371 #13881]  INFO -- : Writing
/home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-02-e5106e911d8a0289bfaf2ac64308a640.jpg
> rendered templates I got:
>   <meta content="8XQYBZWrTxmfdGvQYCK0JwQDfr2pt8si+FjW4a30SsA=" name="csrf-token"
/></head><body>
>     = javascript_include_tag "application", params[:controller]
>   config.consider_all_requests_local       = false
>
> end
>
> What I need to configure to have stylesheet_link_tag and
> javascript_include_tag pick the right assets location on production?
>
> Thanks
>

When you are using a server that serves directly from your application
such
as WEBrick or Thin, you will need to set config.serve_static_assets to
true
in order to have it serve files from the public directory.  This inserts
middleware into the Rack stack to first check the public directory so it
adds overhead.

This is not necessary when you are running through a true web server
such
as Apache or Nginx as the web server will automatically serve files from
the public directory on its own.  config.serve_static_assets=true adds
overhead to your app so when you deploy to a true web server, it's
generally best to set this to false.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.