LoginSignup
1
0

More than 5 years have passed since last update.

Rails 5でGoogle Adsenseを表示する

Posted at

Rack CorをGemにかいてbundle i

gem 'rack-cor'

そして、下記のファイルを作る。

config/initializers/cors.rb
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'https://googleads.g.doubleclick.net'
    resource '*',
      headers: :any,
      methods: %i(get options head)
  end
end

下記はただ単純にAdsenseで生成されたコードをSlimにして必要箇所にrenderしただけ。

_ad_landing.slim
script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"

ins.adsbygoogle data-ad-client="YOUR-AD-CLIENT" data-ad-slot="YOUR-SLOT" style="display:inline-block;width:336px;height:280px"

javascript:
  (adsbygoogle = window.adsbygoogle || []).push({});

何かオススメの実装方法があれば、教えていただけますと嬉しいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0