Write css codes distinct from different pages

29/Aug/2013 · 1 minute read

In rails, there is normally a view corresponding to an action. So if you want to do some special styles based on different pages, you can render controller name and action name in your layout file like this:

<body class="#{controller_name} #{action_name}">
  <!-- Render something -->
</body>

Let’s assumpt that your current page controller is ProductsController, and your action is index, then you can write your style codes like:

.products.index {
  /* some styles */
}
版权声明:本文为原创文章,转载请注明来源:《Write css codes distinct from different pages - Hackerpie》,谢绝未经允许的转载。