V
V
vadimstroganov2016-03-03 10:44:00
Ruby on Rails
vadimstroganov, 2016-03-03 10:44:00

How to fix asset display in multisite rails app?

Hello!
I am making a rails application that will serve many sites.
The structure looks like this:

- assets
-- stylesheets
--- site1
--- site2
-- javascripts
--- site1
--- site2
-- images
--- site1
--- site2

-views
-- site1
--- layouts
--- pages
-- site2
--- layout
--- pages

Let before views I define it like this:
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  layout :determine_site
  before_filter :determine_view_path

  private

    def determine_site
      if Rails.env.production?
        @site = Site.find_by :domain_production => request.host
        @site.code if @site.present?
      else
        @site = Site.find_by :domain_local => request.host
        @site.code if @site.present?
      end
    end

    def determine_view_path
      prepend_view_path ["#{Rails.root}/app/views/#{determine_site}"]
    end

end

When developing on the local machine, everything is fine. All assets are there.
After deploying to production, all assets are not displayed on the sites, even rails_admin is bare.
In assets.rb:
Rails.application.config.assets.precompile += %w( ckeditor/* )
Rails.application.config.assets.precompile += %w( site1/*.css site1/*.js )
Rails.application.config.assets.precompile += %w( site2/*.css site2/*.js )

What am I doing wrong? Please tell me how to solve the problem with
UPD assets.
On the server, in /shared/public/assets/ assets are generated, but for some reason, the links that lead to them return 404 not found
0802488aebf24ce2bf670cb8ef833aa1.png
UPD.2
by clicking on a direct link, it opens. If this file is already thrown into the assets directory, then the request for the test.css file gives 404
UPD.3
The problem is solved. It turns out that the sysadmin configured the location incorrectly in nginx.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2016-03-03
@IvanTheCrazy

How are assets connected?
if something like
= stylesheet_link_tag 'application', media: 'all' is left,
then you need to redo it a little differently:
= stylesheet_link_tag "site1/application", : media => "all"
works fine for me this way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question