Skip to content

Instantly share code, notes, and snippets.

@crova
crova / Error message
Created December 6, 2017 20:46
Getting error on Segments#new
NoMethodError in Segments#new
Showing /home/crova/Shelter/Dev/the-nuclear-shelter/app/views/segments/_form.html.erb where line #16 raised:
undefined method `segment' for #<Segment id: nil, created_at: nil, updated_at: nil>
Extracted source (around line #16):
14
15
16
17
18
def update
# Calculate the KPIs for a single_shoot
@single_shoot = SibCampaign.find_by_id(params[:id])
@single_shoot.orate = (@single_shoot.unique_views / @single_shoot.sent) * 100
if @single_shoot.update_attributes(single_shoot_params)
@single_shoot = SibCampaign.find_by_id(params[:id])
@single_shoot.cost = (@single_shoot.sent * @single_shoot.cpm) / 1000
@single_shoot.turnover = @single_shoot.result * @single_shoot.payout
@single_shoot.margin = (@single_shoot.turnover - @single_shoot.cost)
@single_shoot.ecpm = (@single_shoot.margin / @single_shoot.sent) * 1000
@crova
crova / db_campaigns_controller.rb
Created December 8, 2017 16:14
orate and crate not being calculated
def update
respond_to do |format|
@single_shoot = DbCampaign.find_by_id(params[:id])
if @single_shoot.update(db_campaign_params)
format.html { redirect_to @single_shoot, notice: 'Campaign was successfully updated.' }
format.json { render :show, status: :ok, location: @single_shoot }
calculate_kpi
else
format.html { render :edit }
format.json { render json: @single_shoot.errors, status: :unprocessable_entity }
@crova
crova / db_campaigns_controller.rb
Created December 8, 2017 18:14
How to create a scope for this query?
def index
# Set Scenario for the Dashboard
#
# Excludes campaigns that belongs to "Un Jour Une Astuce" program
ids_to_exclude = [864, 5, 7, 866, 8, 994, 868, 14, 870, 15, 17, 11, 16, 21, 23, 24, 25, 31, 20, 871, 29, 30, 27, 38, 1540, 34, 35, 37, 33, 872, 41, 43, 65, 42, 46, 47, 48, 995, 45, 873, 51, 53, 874, 50, 875, 58, 876, 59, 55, 877, 63, 878, 64, 61, 879, 68, 69, 67, 880, 73, 885, 74, 71, 881, 77, 79, 76, 882, 83, 883, 84, 81, 884, 101, 886, 103, 99, 887, 106, 107, 996, 105, 888, 110, 111, 127, 109, 889, 116, 1653, 1566, 113, 890, 119, 120, 891, 118, 892, 124, 125, 126, 123, 893, 132, 894, 129, 895, 135, 136, 146, 134, 896, 141, 897, 906, 138, 898, 145, 899, 143, 900, 151, 1571, 157, 149, 902, 154, 155, 156, 153, 904, 907, 161, 193, 1631, 909, 166, 911, 1482, 164, 1636, 169, 170, 171, 168, 913, 174, 176, 1497, 173, 1638, 179, 180, 563, 178, 915, 183, 184, 1588, 182, 917, 187, 188, 564, 186, 919, 192, 921, 190, 923, 197, 925, 195, 927, 202, 929, 200, 931, 206, 935, 204, 937, 209, 210, 224,
@crova
crova / API response
Last active December 11, 2017 18:00
Problem with table name "invalid"! How to save "invalid" from API response to the column "invalid_sent" from database
{"requests"=>5851, "delivered"=>5656, "bounces"=>194, "invalid"=>11, "deferred"=>46, "opens"=>2705, "unique_opens"=>1500, "clicks"=>158, "unique_clicks"=>140, "date"=>"2017-11-25", "tag"=>"WM-ABD-2018-GMAIL-E-CIA"}
@crova
crova / camps_to_update_controller.rb
Created December 13, 2017 11:40
Why this works for one Model (SibTransac) and don't work for the other (DbCampaign)?!
def update
def db_campaign
@db_campaign = DbCampaign.find_by_id(params[:id])
end
respond_to do |format|
@db_campaign = DbCampaign.find_by_id(params[:id])
if @db_campaign.update(db_campaign_params)
format.html { redirect_to @db_campaign, notice: 'Campaign was successfully updated.' }
format.json { render :show, status: :ok, location: @db_campaign }
calculate_kpi
@crova
crova / _menu.html.erb
Created January 2, 2018 13:11
Can't see why the dropdown menu works for a few items and not others
<!DOCTYPE html>
<html>
<head>
<title>The Nuclear Shelter</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
@crova
crova / Above file returns following error
Last active January 2, 2018 19:51
Can't figure what is going on here
undefined method `tag' for [:requests, 0]:Array
@crova
crova / controller.rb
Created January 4, 2018 13:43
Update routine not evaluating the field "date" and end up creating a new record instead of updating the existing one on the database
def sib
@sib ||= Mailin.new("URL","APIKEY")
end
def shoot_criteria_gmail_e_cia_collecte
{ "aggregate" => 0, "tag" => "WM-ABD-2018-GMAIL-E-CIA-COLLECTE", "days" => 3 }
end
def shoots_gmail_e_cia_collecte
@shoots_gmail_e_cia_collecte ||= sib.get_statistics(shoot_criteria_gmail_e_cia_collecte)
end
@crova
crova / dbase_schema.rb
Created January 8, 2018 14:56
Can't figure why I end up with multiple records for the same date
reate_table "sib_transacs", force: :cascade do |t|
t.integer "requests"
t.integer "delivered"
t.integer "bounces"
t.integer "spamreports"
t.integer "blocked"
t.integer "invalid_sent"
t.integer "deferred"
t.integer "opens"
t.integer "unique_opens"