0

I am using Rails-4.0.2, ruby 2.1.0 and have several public files, which are in my app/public folder. In index.html view I have the following form for downloading it.

<table class="table table-condensed table-striped" style="border-collapse: collapse;
      border-spacing: 0; width: 50%;">
  <tbody>
    <% @reports.each do |report| %>
      <tr>
        <td><%= report.title %></td>
        <td> <a href=<%= "#{report.url}"%>> Download </a></td>
      </tr>
    <% end %>
  </tbody>

In the HTML code I have got the following link:

<a href="reports/2014-01-22-13:45:13-UTC.xlsx">Download</a>

When I am clicking on this link during development stage on 127.0.0.1:3000 browser is downloading this file. That is what I need.

But when I am clicking during production stage on the same address 127.0.0.1:3000 I have got the following error:

Started GET "/reports/2014-01-22-13:45:13-UTC.xlsx" for 127.0.0.1 at 2014-01-22 17:50:13 +0400
Processing by ReportsController#show as XLSX
 Parameters: {"id"=>"2014-01-22-13:45:13-UTC"}
 Completed 404 Not Found in 2ms

 ActiveRecord::RecordNotFound (Couldn't find Report with 
 id=2014-01-22-13:45:13-UTC):
 app/controllers/reports_controller.rb:60:in `set_report'

This is just a static file in public folder, how can I download it in production?

Here is my config files:

Development:

GetLead::Application.configure do
  config.cache_classes = false
  config.eager_load = true
  config.serve_static_assets = true

  config.assets.initialize_on_precompile = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = false
  config.assets.compress = true
  config.assets.compile = true

  config.assets.digest = true
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
end

Production:

GetLead::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.compress = true
  config.assets.compile = true
  config.assets.digest = true
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

Thanks in advance!

1 Answer 1

1

The File won't be delivered in Production because

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false

I recommend you use a real webserver (like nginx or Apache) to deliver static files! (As a starting point for configuring nginx see http://wiki.nginx.org/RubyonRailsMongrel or Google)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.