Last active
August 29, 2015 14:05
-
-
Save rishighan/c7d05d13d62131d51fad to your computer and use it in GitHub Desktop.
How to create a hash from a collection in the view ?
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
h =[] | |
@posts.each do |p| | |
p.categories.each do |cat| | |
h << {p.id => cat.title} | |
end | |
end |
Author
rishighan
commented
Aug 13, 2014
To achieve the deisred result
[30=>{"General", "Technical"}, 40 => {"Technical"}]
use
@log.map { |p| [p.id, p.categories.map(&:title)] }.to_h
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment