使用自定义模板rails3

时间:2010-11-18 23:21:13

标签: ruby-on-rails-3 saas subdomain

我正在设置SAAS解决方案,因为每个帐户都有自己的子域,例如sub1.mydomain.com sub2.mydomain.com和我在应用程序模板中设置了一个标准的2列模板,我希望在旁边的列中包含每个站点的自定义部分,以及自定义的style.css文件每个子域名。 所以我想知道如何设置它以显示自定义信息。我想设置一个样式控制器 - 所以它只显示左侧边栏的项目,以及与之关联的每个域名的style.css页面是否有人有任何好的想法?

基本上对于静态页面控制器我已经有了这个设置,以及另一个DB动作 但任何提示将不胜感激。

1 个答案:

答案 0 :(得分:1)

看看我正在处理的项目:https://github.com/fabiob/guildhost-hosting

您需要的代码位于app/controllers/application_controller.rb

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

同样在app/views/layouts/application.html.erb

<!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文件,则@import上应使用main.css个子句。

相关问题