samedi 21 mars 2015

The has_many :through Association Show view

I would like to sites / show / 1 see all campaigns that belong to each page. The console itself has created Realization Campaign Site



Realization Load (0.4ms) SELECT `realizations`.* FROM `realizations` WHERE `realizations`.`id` = 2 LIMIT 1
=> #<Realization id: 2, site_id: 1, campaign_id: 2, impressions: nil, clicks: nil, created_at: "2015-03-20 11:29:59", updated_at: "2015-03-20 11:29:59">

Campaign Load (0.3ms) SELECT `campaigns`.* FROM `campaigns` WHERE `campaigns`.`id` = 2 LIMIT 1
=> #<Campaign id: 2, name: "Adidas", from: nil, to: nil, impression: nil, click: nil, ff: nil, created_at: "2015-03-20 11:29:19", updated_at: "2015-03-20 11:29:19">

Site Load (0.4ms) SELECT `sites`.* FROM `sites` WHERE `sites`.`id` = 1 LIMIT 1
=> #<Site id: 1, name: "eskago.pl", use: nil, booked: nil, alldeclaration: nil, declaration: nil, created_at: "2015-03-20 11:28:59", updated_at: "2015-03-20 11:28:59">


Model looks



class Realization < ActiveRecord::Base
belongs_to :site
belongs_to :campaign
end
class Site < ActiveRecord::Base
has_many :realizations
has_many :campaigns, through: :realizations
end
class Campaign < ActiveRecord::Base
has_many :realizations
has_many :sites, through: :realizations
end


In the model realization I gives the number of impressions and clicks . So that the amount was set for the page


The Site/show/1 I would like to display the name of the campaign , the number of impressions and number of clicks .


Please help should look like controller site/show, and a view of the show


Aucun commentaire:

Enregistrer un commentaire