Last active
August 29, 2015 14:05
-
-
Save rishighan/6c0775aea7fbc525ae40 to your computer and use it in GitHub Desktop.
How to check for existence of element in a collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@log.last.categories | |
=> #<ActiveRecord::Associations::CollectionProxy [#<Category id: 1, title: "General", description: "Toto", created_at: "2014-07-25 19:09:17", updated_at: "2014-07-30 14:50:42">, #<Category id: 6, title: "Highlight", description: "Some shenanigans on the way to the graveyard.", created_at: "2014-08-12 15:56:42", updated_at: "2014-08-12 15:56:42">]> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@log = Post.is_draft("no").group_by_category("exclude", ["Projects", "Hero", "Feature"]).page(params[:page]).per(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to check the existence of "Highlight" in the collection, and then based on the presence display a certain style in the view.
So,
I want to be able to do something like: