I would like to combine data retrieved from an API with local database data in a new JSON. But I think I'm doing this wrong. Here is my code :
@data = ActiveSupport::JSON.decode(@api_data)
@data.each do |key|
if key['state'] == "active"
user_id = key['id']
user_database = User.where(:user_id => user_id).take
@userlist = []
unless user_database.blank?
user_data = {
:user_id => key['id'],
:enrolement_start_date => key['start_at'],
:enrolement_end_date => key['end_at'],
:user_interest => user_database.interests,
:user_discipline_id => user_database.discipline_id,
}
@userlist.push(user_data)
end
end
end
@userlist = @userlist.to_json
Actually, it's working but I only receive the last user as result. I don't figure how to make it works :-/ Many thanks in advance !
@courselistdefined, is it supposed to be there?takebecausetakerequires one parameter. Check the value ofuser_databaseafter that call.:user_id => key['id'],and the other two lines after it, notice the rocket notation.user_databasereturns me an object#<User:0x000000037e1820>