I want to change the aspect of some html elements representing table rows from a model. In particular, my Component
model has a :rating
column:
create_table "components", force: true do |t|
t.string "name"
t.string "description"
t.string "repository_url"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "rating", default: 5 # color in the view to be defined by this value
end
And, in the view, the existing components (Component.all
) are rendered as links:
- @components.each do |components|
= link_to component.name, component, class: "rating_#{component.rating}"
As you can imagine, the way I am handling this by defines the style for rating_1
...rating_10
in the corresponding css file:
.componenttag.rating_1 {
background-color : black
}
...
.componenttag.rating_10 {
background-color : green
}
This works as a simple solution, but I have the impression that there is a better (and more elegant) way of solving this problem or other similar ones. Am I wrong? :)
Thanks in advance.