Answer the question
In order to leave comments, you need to log in
How can I implement themes with separate views and assets in rails?
Hello!
How can I implement themes with separate views and assets in rails?
Is it possible to make the generators also take into account the path to the topic?
We are talking about the simultaneous use of only one theme, but so that it is easy to switch them from the config.
Unfortunately, no definitive solution could be found.
Answer the question
In order to leave comments, you need to log in
It turned out something like this:
# config/application.rb
config.theme = 'default'
config.assets.paths << Rails.root.join('app/themes', config.theme, 'assets/javascripts')
config.assets.paths << Rails.root.join('app/themes', config.theme, 'assets/stylesheets')
config.assets.paths << Rails.root.join('app/themes', config.theme, 'assets/images')
config.assets.paths << Rails.root.join('app/themes', config.theme, 'assets/bower_components')
# app/controllers/application_controller.rb
prepend_view_path Rails.root.join('app/themes', Rails.application.config.theme, 'views')
Stylesheets in a Rails application are usually included in a tag using the stylesheet_link_tag helper . Pass a file name to this helper based on the current theme selected by the user. For example:
, where the theme name is stored in ui_theme , and the corresponding stylesheet file is in the app/assets/stylesheets directory. Well, at least that's what I would do.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question