Pregunta

I have installed the less-rails gem as I am keen to use the colour manipulation LESS offers. I need to extract a colour from my database as my themes base colour, and build up from there.

I have the static CSS, and have renamed it styles.css.less to ensure that rails understands the less extension, which it appears to.

The next thing I tried was to also wrap the file as an erb, to hopefully allow ruby string literals to process before being sent to LESS, and eventually outputting as valid CSS (still with me?)

The file is now called style.css.less.erb. While the file simple contains valid CSS, the processing of the document works. As soon as I add a ruby string literal, it fails.

color: #{"#112233"};

In the chrome debugger, nothing after this line is getting processed.

What am I doing wrong, and how should I do what I am trying to do?

¿Fue útil?

Solución

As Chowlett says in comments, you should use erb syntax: <%= "#112233" %> Next step is get that value from db. If this color value is application-wide, probably you are looking for settings in db solution. I use rails-settings-cached gem for that. Your result code will looks like

color: <%= Setting.foo_color %>

If you are using assets on production, don't forget to recompile them after each setting change.

And if it's not a setting but probably something specific to each user then you can't use application-wide css files for that, but you can write inline css in views.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top