-
-
Save farleyknight/998401 to your computer and use it in GitHub Desktop.
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
def index | |
@carriers = Carrier.all.sort_by(&:name) | |
@lines = Array.new | |
@carriers.each do |c| | |
c.sw_profiles.each do |p| | |
@lines.push(prepend_hash_keys("carrier", c.attributes).merge(prepend_hash_keys("sw_profile", p.attributes))) | |
end | |
end | |
end | |
def prepend_hash_keys(name, hash) | |
h = {} | |
hash.each do |k, v| | |
h["#{name}_#{k}"] = v | |
end | |
h | |
end | |
# which results in | |
[{Carrier id: ... name: ...} => {SWProfile id: ... name: ...}...] | |
# what I need is a new Array: | |
[{NewHash carrier_id: ... carrier_name: ... sw_profile_name: ... ...}, {} ...] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment