views:

241

answers:

3

I have a site built in Ruby On Rails which has many ads in different templates and views. It is hard to actualy remove each ad between tests and deployments.

I don't know whether Google approves many impressions (even if without clicks) on localhost.

How do you deal with this issue?

Maybe it is a good solution to set a variable/constant available everywere to enable/disable ads easily. Do you think it is a good solution? If so, how do I declare a global variable for views?

A: 

May be it is childish, but one thing you can do is... when you are on localhost..disconnect from internet :)

Webbisshh
I always need to be connected to solve problems when they come out ;)
collimarco
+5  A: 

I'm pretty sure displaying ads locally is fine as long as you don't click them. I've displayed ads locally on a few projects and I have yet to be shut down by the man.

I don't have the exact same issue, I have ads enabled/disabled for different types of accounts - I just put the ad code in a partial.

You could create a partial like this:

<% unless ENV['RAILS_ENV'] == "development" %>

ad code here.

<% end %>

If you're doing this in more than one place I'd create a helper method:

def display_ads?
  ENV['RAILS_ENV'] != "development"
end

Then your partial code would become this:

<% if display_ads? %>

ad code here.

<% end %>
Andy Gaskell
you could go one step further with that helper and use a blockdef display_ads if ENV['RAILS_ENV'] != "development" yield endendand in the partial:<% display_ads do %> <div> Buy Pepsi </div><% end %>
Tilendor
Nice - I like it!
Andy Gaskell
+4  A: 

One thing you can do is go to the Allowed Sites settings at AdSense (it’s in the AdSense Setup > Allowed Sites tab) and check the “only allow certain sites to show ads for my account” option, and then add all the domains where AdSense is allowed to appear, without including localhost or any other development, staging or non-production domains, obviously.

If you put your ad code on a page not on this list, ads will still show, but impressions and clicks will not be recorded.

That way you can have ads in your development environment without worrying about accidentally clicking on your ads, and without skewing your AdSense stats.

Guillermo Esteves