Skip to content

Instantly share code, notes, and snippets.

@crova
crova / controller
Last active June 13, 2016 07:20
trying to update from form
class CampaignController < ApplicationController
def index
@campaigns = Campaign.all.sorted.paginate(:page => params[:page], :per_page => 10)
end
def show
@single_shoot = Campaign.find(params[:id])
# KPIs
#
@crova
crova / actual select tag
Last active June 15, 2016 19:43
How to populate select list with data from a specific model?
<tr>
<th><%= f.label(:deal) %></th>
<td><%= f.select(:deal, options_for_select([['CPL', 'CPL'], ['CPC', 'CPC'], ['CPM', 'CPM'], ['CTL', 'CTL'], ['CPA', 'CPA']]), :value => @single_shoot.deal) %></td>
</tr>
@crova
crova / controller
Created June 16, 2016 18:50
How to update all records on the future but only evaluate 'campaign_id' to check if record already exists?
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
day = Time.current.day
day_to_use = day - 1
month = Time.current.month
#sets number of days within current month
if month == 4 || 6 || 9 || 11
days_within_month = 30
elsif month == 1 || 3 || 5 || 7 || 8 || 10 || 12
days_within_month = 31
else
days_within_month = 28
@crova
crova / Controller
Created January 30, 2017 04:26
How to run this task with delayed_job
# fetchs SIB Account information
def sib_account_fetch
sib = Mailin.new("API_URL","API_KEY")
acct = sib.get_account()
acct.dig('data')
credits = acct.dig('data', 0).to_h
SibAccount.find(1).update_attributes(credits)
details = acct.dig('data', 2).to_h
SibAccount.find(1).update_attributes(details).delay
@crova
crova / Routine wanted as Back Job
Last active February 1, 2017 04:12
Trying to get a Back Job working
# Fetchs campaigns from SiB
class CampaignFetch
def get
def sib
@sib ||= Mailin.new("API_URL","API_KEY")
end
def shoot_criteria
{ "type"=>"classic", "status" => "sent", "page"=>10,"page_limit"=>1000 }
@crova
crova / dashboard_controller.rb
Last active June 23, 2017 13:38
Is there a clever way to organize this controller?
# Generates KPIs for each Month - Year 2016
#january kpis
camp_january_2016 = DbCampaign.where('extract(month from scheduled_date) = ?', 01).where('extract(year from scheduled_date) = ?', 2016)
camp_january_actifs_2016 = DbCampaign.where('extract(month from scheduled_date) = ?', 01).where('extract(year from scheduled_date) = ?', 2016).where(:segment_2016 => "Actifs")
jan_o_2016 = camp_january_2016.pluck('unique_views').sum
jan_opens_2016 = jan_o_2016 + 0.0
jan_c_2016 = camp_january_2016.pluck('clicker').sum
jan_clicks_2016 = jan_c_2016 + 0.0
jan_v_2016 = camp_january_2016.pluck('sent').sum
jan_volume_2016 = jan_v + 0.0
@crova
crova / single-post.php
Created July 5, 2017 12:11
How to make 2 buttons out of those options "previous" and "next" ?
<?php
wp_link_pages( array(
'before' => '<div class="page-links"><center><p id="post-navigator">' . esc_html__( '', 'extra' ),
'after' => '</p></center></div>',
'next_or_number'=>'next',
'previouspagelink'=>'&laquo; P&aacute;gina anterior',
'nextpagelink'=>'Continuar lendo &raquo;',
) );
?>
@crova
crova / Camp_data Object
Last active October 21, 2017 19:22
How to save the needed data to model
[{"Stat"=>{"affiliate_info1"=>nil, "approved_payout"=>"277.000000"}, "Offer"=>{"name"=>"Johnson&Johnson Promo - BR"}}, {"Stat"=>{"affiliate_info1"=>"", "approved_payout"=>"99.003150"}, "Offer"=>{"name"=>"Toluna - BR"}}, {"Stat"=>{"affiliate_info1"=>"", "approved_payout"=>"54.000000"}, "Offer"=>{"name"=>"eCGlobal - 168742 - Tecnologia - BR"}}, {"Stat"=>{"affiliate_info1"=>"", "approved_payout"=>"11.850000"}, "Offer"=>{"name"=>"Clube da Lu - BR"}}, {"Stat"=>{"affiliate_info1"=>"", "approved_payout"=>"81.250000"}, "Offer"=>{"name"=>"Conecta í Uber - BR"}}, {"Stat"=>{"affiliate_info1"=>"BASE", "approved_payout"=>"104.751760"}, "Offer"=>{"name"=>"Global Test Market - BR"}}, {"Stat"=>{"affiliate_info1"=>"SUBID", "approved_payout"=>"10.500000"}, "Offer"=>{"name"=>"Eudora - BR"}}, {"Stat"=>{"affiliate_info1"=>"SUBID", "approved_payout"=>"397.928968"}, "Offer"=>{"name"=>"Angela - BR"}}, {"Stat"=>{"affiliate_info1"=>"subid", "approved_payout"=>"498.369118"}, "Offer"=>{"name"=>"Mundo de Opiniões - BR"}}, {"Stat"=>{"affi
@crova
crova / fetcher_controller.rb
Created December 6, 2017 16:34
Why does it work on Console but not on App?
# Fetchs campaigns from SiB
class SibCampaignFetcher
# fetchs SIB Campaigns
# Starts SiB Communication
def sib
@sib ||= Mailin.new("URL","APIKEY")
end
# Define the data to collect