は、私が働いているプロジェクトを見てみましょう:あなたが必要https://github.com/fabiob/guildhost-hosting
コードがapp/controllers/application_controller.rb
である:
app/views/layouts/application.html.erb
でも
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :load_subdomain
def load_subdomain
@subdomain = self.request.subdomains[0] || 'local'
load_customer
raise "Invalid Subdomain: #{self.request.subdomains}" unless @subdomain.present?
end
def load_customer
@customer = Customer.find(@subdomain)
end
end
:
<!DOCTYPE html>
<html>
<head>
<title><%= @customer.name %> @ MySaaS.com.br</title>
<%= stylesheet_link_tag :all %>
<%= stylesheet_link_tag "/themes/#{@subdomain}/main.css" %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
...
</body>
</html>
/public/themes
があります各サブドメインのカスタマイズが存在するフォルダ。各サブドメインには、単一のCSSをカスタマイズする機会があります(main.css
)。複数のCSSファイルが必要な場合はmain.css
に@import
句を使用する必要があります。
私は今度はbeforeフィルタタグを持っているので、どういうわけか各アクションからグローバルIDを見つけることができますか? @accountid = Account.find_by_subdomain!(request.subdomain).id – tspore