Search code examples
ruby-on-railsruby-on-rails-3.2slim-lang

Using slim with rails


rails 3.2

I am new to slim, and I have to work with an application that's using it. Reading through some documentation, I see that using something like:

.class

which translates to:

<div class="class"></div>

In the code I inherited, in the .html.slim file, I have:

.form-section.customer_info

When I look through the stylesheets folder, I cannot find customer_info, but I can find form-section.

Shouldn't I be able to find customer_info in one of the stylesheets?


Solution

  • The answer is maybe you can find it in a stylesheet. But there are other cases, where you may not:

    • Sometimes a class is used as a target for a JavaScript snippet; if you find it mentioned in the javascript for the app, then you likely want to keep it because an interaction may depend on it (read the JS code to determine this).
    • Sometimes, the class has been removed from the stylesheet and not removed from the code; in this case you may remove it.
    • However, sometimes a class is added to mark the section of HTML as semantically significant so that styling can be applied to it at a future time; in that case, you may choose to keep it.

    For instance, for better or ill, when I am writing code, I will name sections using classes, as .user-list or .part-table to indicate that, as the coder, I know the HTML code is going to contain users or parts. By doing this consistently I can mark out portions of the front end for later consistent styling by usage; that is, all the part tables can be styled the same way, all the user lists can be styled the same way, etc. Again, this is a convention I have seen used and that I practice. Nonetheless, these represent a few reasons why a class may be present in the HTML, but not referenced elsewhere.