Rails给予每个用户自己的可自定义样式表 [英] Rails Giving Each User Their Own Customizable Stylesheet

查看:165
本文介绍了Rails给予每个用户自己的可自定义样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个相当直接的问题。

This is a fairly straightforward question.

我在Rails3应用程序中有用户。我想给每个用户通过表单自定义他们的样式表的能力,因此他们基本上可以有自己的主题。

I have Users in my Rails3 Application. 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?

我需要使用LessCss吗?如果是这样,我可以将控制器中的变量传递给lesscss sylesheet吗?

Would I need to use LessCss and if so, can I pass variables from a controller to the lesscss sylesheet?

推荐答案

尽管听起来像一个可怕的想法,我想一个简单的方法是添加一个CSS表和映射到每个CSS文件的记录的用户。创建新用户时,使用默认CSS为每个文件创建新记录。

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. When a new user is created you create new records for each file using the default CSS.

要编辑,您可以在页面上向用户显示CSS文本,其中有一些样本小页面,可以看到实时更改。然后你需要动态加载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. 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.

再一次,虽然,这是一个可怕的想法在我看来。当用户混乱,然后不能使用网站,因为他们带来一些坏的价值,会发生什么?他们不能改变回来,因为他们看不到什么,他们做什么?他们永远不会回来。

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.

这篇关于Rails给予每个用户自己的可自定义样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆