mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Conditional Class Selectors in Haml as a rails til.
This commit is contained in:
@@ -53,6 +53,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
- [Attribute Getter without the Recursion](rails/attribute-getter-without-the-recursion.md)
|
||||
- [Attribute Was](rails/attribute-was.md)
|
||||
- [Capybara Page Status Code](rails/capybara-page-status-code.md)
|
||||
- [Conditional Class Selectors in Haml](rails/conditional-class-selectors-in-haml.md)
|
||||
- [Creating Records of Has_One Associations](rails/creating-records-of-has-one-associations.md)
|
||||
- [Show Pending Migrations](rails/show-pending-migrations.md)
|
||||
|
||||
|
||||
21
rails/conditional-class-selectors-in-haml.md
Normal file
21
rails/conditional-class-selectors-in-haml.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Conditional Class Selectors in Haml
|
||||
|
||||
You can assign a class selector to a tag in HAML like so:
|
||||
|
||||
```ruby
|
||||
%div.active
|
||||
```
|
||||
|
||||
You can conditionally assign a class selector in a concise manner like so:
|
||||
|
||||
```ruby
|
||||
%div{ class: ( "active" if @thing.active? ) }
|
||||
```
|
||||
|
||||
You can do multiple conditional class selectors with array syntax:
|
||||
|
||||
```ruby
|
||||
%div{ class: [ ("active" if @thing.active?), ("highlight" if @thing.important?) ] }
|
||||
```
|
||||
|
||||
[source](http://stackoverflow.com/questions/3453560/append-class-if-condition-is-true-in-haml-with-rails)
|
||||
Reference in New Issue
Block a user