将样式切换器添加到 Rails App 管理部分?

发布于 2024-09-11 14:31:17 字数 378 浏览 0 评论 0原文

我最近一直在开发一个名为 BaseApp2 的 Rails 模板。你可以在 GitHub 上看到它: http://github.com/dannyweb/BaseApp2

有一个管理员部分设置允许管理用户,我正在研究通过管理部分向公共站点添加公告的能力。

我真正想做的是为界面提出两到三种替代配色方案,并允许管理员选择他们喜欢的并选择它。所选的配色方案将从那时起向所有用户显示。

我真的不知道如何去做这件事 - 理想情况下,我正在寻找某种教程或同样适合初学者的东西。

提前致谢!

谢谢,

丹尼

I have been working on a Rails template recently called BaseApp2. You can see it on GitHub here: http://github.com/dannyweb/BaseApp2

There is an administrators section setup which allows the management of Users and I am working on the ability to add announcements to the public site via the admin section.

What I would really like to do, is come up with two or three alternative colour schemes for the interface and allow the administrator to choose which they prefer and select it. The chosen colour scheme would then show for all users from then on.

I have literally no idea how to go about doing this - ideally I am looking for a tutorial of some sort or something equally beginner-esque.

Thanks in advance!

Thanks,

Danny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似梦非梦 2024-09-18 14:31:17

这应该相当容易,并且有很多方法可以做到。您需要将该首选项保存在某处。也许可以向您的用户/人员模型添加一个属性来指定该偏好。在您的管理布局模板中,根据该首选项,添加额外的样式表。或者,将一个类添加到正文标记,并在样式表中对样式进行子类化:

body {
  background-color: white;
}

body.sunshine {
  background-color: yellow;
}

布局模板:

<%= stylesheet_link_tag(current_user.theme) if current_user.theme %> 

<body class="<%= current_user.theme || '' %>">

It should be fairly easy and there are many ways to do it. You will need to save that preference somewhere. Maybe add an attribute to your user/person model that will specify that preference. And in your admin layout template, based on that preference, add an additional stylesheet. Or, add a class to the body tag and in your style sheet subclass the styles:

body {
  background-color: white;
}

body.sunshine {
  background-color: yellow;
}

The layout template:

<%= stylesheet_link_tag(current_user.theme) if current_user.theme %> 

or

<body class="<%= current_user.theme || '' %>">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文