Created
June 16, 2016 18:50
-
-
Save crova/6ad69e7a4f2005965e3b4a7c620d17e0 to your computer and use it in GitHub Desktop.
How to update all records on the future but only evaluate 'campaign_id' to check if record already exists?
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 campaign_query | |
@campaign_query = Shoot.all | |
end | |
def campaign_trial | |
@campaign_trial = campaign_query.order("id ASC") | |
end | |
def needed_campaign_records | |
@needed_campaign_records ||= campaign_trial.map | |
end | |
def campaigns_fetch | |
# update/create | |
needed_campaign_records.each do |record| | |
campaigns = Campaign.find_or_create_by(:campaign_id => record['campaign_id'], campaign_name: record['campaign_name'],subject: record['subject'], sent: record['sent'],scheduled_date: record['scheduled_date'],tags: record['tags'],delivered: record['delivered'],unique_views: record['unique_views'],viewed: record['viewed'],clicked: record['clicked'],clicker: record['clicker'],hard_bounce: record['hard_bounce'],soft_bounce: record['soft_bounce'],unsub: record['unsub'],mirror_click: record['mirror_click'],complaints: record['complaints']) | |
# updated_campaigns = campaigns(campaign_id: record['campaign_id'],campaign_name: record['campaign_name'],subject: record['subject'], sent: record['sent'],scheduled_date: record['scheduled_date'],tags: record['tags'],delivered: record['delivered'],unique_views: record['unique_views'],viewed: record['viewed'],clicked: record['clicked'],clicker: record['clicker'],hard_bounce: record['hard_bounce'],soft_bounce: record['soft_bounce'],unsub: record['unsub'],mirror_click: record['mirror_click'],complaints: record['complaints']) | |
unless campaigns.save(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
flash[:notice] = "Shoots updated successfully." | |
redirect_to(:controller => 'monet', :action => 'refresh') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment