简体   繁体   English

Rails为每个用户提供自己的可定制样式表

[英]Rails Giving Each User Their Own Customizable Stylesheet

This is a fairly straightforward question. 这是一个相当简单的问题。

I have Users in my Rails3 Application. 我的Rails3应用程序中有用户。 I want to give each user the ability to customize their stylesheet through a form so they can essentially have their own themes. 我想让每个用户都可以通过表单自定义样式表,这样他们就可以拥有自己的主题。

I was wondering how I can go about getting this to happen and what is the best way that you have seen it done? 我想知道如何才能做到这一点,您看到它完成的最佳方法是什么?

Would I need to use LessCss and if so, can I pass variables from a controller to the lesscss sylesheet? 我是否需要使用LessCss,如果可以,可以将变量从控制器传递到lesscss sylesheet吗?

Despite that sounding like a terrible idea I guess an easy way to do it would be to add a CSS table and map it to the user with a record for each CSS file. 尽管这听起来像一个可怕的主意,但我想一个简单的方法是添加一个CSS表并将其映射到用户,并为每个CSS文件添加一条记录。 When a new user is created you create new records for each file using the default CSS. 创建新用户后,您将使用默认CSS为每个文件创建新记录。

To edit you could present the user with the CSS text on a page with some sample mini-page where they could see the changes happen live. 要进行编辑,您可以在带有一些示例微型页面的页面上向用户显示CSS文本,使他们可以实时看到更改。 You would then need to load the CSS dynamically which could be a huge hit on your database so you'd want to add some memory to the call to retrieve the CSS. 然后,您需要动态加载CSS,这可能会对数据库造成巨大的冲击,因此您需要在调用中添加一些内存以检索CSS。

Again though, this is a horrible idea in my opinion. 不过,我认为这是一个可怕的想法。 What happens when the user messes up and then can't use the site because they put in some bad value? 当用户搞砸了,然后由于价值太高而无法使用该网站时,会发生什么? They can't change it back because they can't see anything so what do they do? 他们无法将其改回,因为他们看不到任何东西,所以该怎么办? They never come back. 他们再也不会回来。

You'd be better off just allowing them to pick from a set of allowed themes. 您最好允许它们从一组允许的主题中进行选择。 But hey, it's your website, you do with it as you please. 但是,嘿,这是您的网站,您可以随意使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM