Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin Dynamic Site Title

Active Admin says you can change the site title this way:

Site Title Options You can update the title or use an optional image in the initializer also. In addition you can set the link. By default there is no link and the title is set to the name of your Rails.application class name.

# config/initializers/active_admin.rb
config.site_title = "My Admin Site"
config.site_title_link = "/"    ## Rails url helpers do not work here
config.site_title_image = "site_log_image.png"

Also, they say you can configure titles by namespace as follows:

ActiveAdmin.setup do |config|
  config.site_title = "My Default Site Title"

  config.namespace :admin do |admin|
    admin.site_title = "Admin Site"
  end

  config.namespace :super_admin do |super_admin|
    super_admin.site_title = "Super Admin Site"
  end
end

I'm building a multi tenant site and I want the site_title to be based on the current tenant name. Is there a way to put a dynamic field in there that changes based on the tenant?

Thanks

like image 778
RailsTweeter Avatar asked Jan 25 '26 20:01

RailsTweeter


1 Answers

I know this is an old question but I've just discovered that you can do the following in the current master of ActiveAdmin:

# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
  ...
  config.site_title = ->(view) {
    # Return what you like from this lambda. Runs in the scope of the controller so you can call your helpers directly.
    # For example, I do something like:
    administrator_signed_in? ? current_tennant.name : "My Site's Generic Name"
  }
  ...
end
like image 50
tristanm Avatar answered Jan 28 '26 17:01

tristanm