Gem Version Code Climate Build Status Dependency Status

Ads Rails

Adds a simple helper to create the google adsense include tag in rails.

Install

Put this line in your Gemfile:

gem 'ads-rails'

Then bundle:

$ bundle

Configuration

Generate the configuration file:

rails g ads:install

The defaults values are:

Ads.configure do |config|
  config.renderer = nil
end

Usage

In your views call the helper like this:

<%= google_adsense_include_tag client: 'pub-1234', slot: '1234', ... %>

All the arguments will be mapped to the the corresponding google_ad variable:

google_ad_client = 'pub-1234'
google_ad_slot = '1234'
.
.
.

NOTE: If environment is not production, will show a gray rectangle.

Renderer

To change the output when the environment is not production, add a custom renderer:

Ads.configure do |config|
  config.renderer = lambda { |options|
    tag(
      :img,
      src: "http://placehold.it/#{options[:width]}x#{options[:height]}&text=Adsense"
    )
  }
end

Credits

This gem is maintained and funded by mmontossi.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.