I store labels/tags in my database (mockup below):
labels:
text:string //name of the label/tag
color:string //hex color of the tag (with '#' at the beggining)
And I have articles, which are connected with this labels. I want to show in my list of articles its tags, but as a colour rectangle (written in css as a block with background-color) – but how set a specified color from database to each box background-color style? I read about some js functions that are changing site background after :click or :hover but still I don’t really know (I barely know js) how to implement it in my app :/ please help!
At the moment I’m just displaying box with the text in it (name of the tag):
- a.labels.each do |l|
.article_tags
= l.text
‘Article_tags’ class is that box, which should change its background to the color taken from db.
1 Answer