Search code examples
cssruby-on-rails-4slim-lang

Setting class dynamically with Rails using Slim


I'm trying to figure out how I can set dynamic classes in slim (Rails 4). This is what I'm trying...based on how I do it in erb.

li class="<%= 'current' if user.id == current_user.id  %>"

Solution

  • This should do!

    li class="#{'current' if user.id == current_user.id}"
    

    Basically, class=anything_that_evaluates_to_string. This works for all kinds of attributes.