advert_selector 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +132 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/advert_selector/application.js +15 -0
  5. data/app/assets/stylesheets/advert_selector/application.css +29 -0
  6. data/app/controllers/advert_selector/application_controller.rb +26 -0
  7. data/app/controllers/advert_selector/banners_controller.rb +122 -0
  8. data/app/controllers/advert_selector/main_controller.rb +13 -0
  9. data/app/controllers/advert_selector/placements_controller.rb +89 -0
  10. data/app/helpers/advert_selector/application_helper.rb +155 -0
  11. data/app/models/advert_selector/banner.rb +107 -0
  12. data/app/models/advert_selector/helper_item.rb +21 -0
  13. data/app/models/advert_selector/placement.rb +58 -0
  14. data/app/views/advert_selector/banners/_form.html.erb +42 -0
  15. data/app/views/advert_selector/banners/edit.html.erb +29 -0
  16. data/app/views/advert_selector/banners/index.html.erb +38 -0
  17. data/app/views/advert_selector/banners/new.html.erb +5 -0
  18. data/app/views/advert_selector/banners/show.html.erb +50 -0
  19. data/app/views/advert_selector/helper_items/_form.html.erb +37 -0
  20. data/app/views/advert_selector/helper_items/edit.html.erb +6 -0
  21. data/app/views/advert_selector/helper_items/index.html.erb +31 -0
  22. data/app/views/advert_selector/helper_items/new.html.erb +5 -0
  23. data/app/views/advert_selector/helper_items/show.html.erb +30 -0
  24. data/app/views/advert_selector/main/index.html.erb +20 -0
  25. data/app/views/advert_selector/placements/_form.html.erb +40 -0
  26. data/app/views/advert_selector/placements/edit.html.erb +6 -0
  27. data/app/views/advert_selector/placements/index.html.erb +25 -0
  28. data/app/views/advert_selector/placements/new.html.erb +5 -0
  29. data/app/views/advert_selector/placements/show.html.erb +20 -0
  30. data/app/views/layouts/advert_selector/application.html.erb +89 -0
  31. data/config/routes.rb +17 -0
  32. data/db/migrate/20120924165938_create_advert_selector_placements.rb +11 -0
  33. data/db/migrate/20120925122858_create_advert_selector_banners.rb +23 -0
  34. data/db/migrate/20120926132649_create_advert_selector_helper_items.rb +18 -0
  35. data/lib/advert_selector.rb +26 -0
  36. data/lib/advert_selector/engine.rb +18 -0
  37. data/lib/advert_selector/errors_cache.rb +21 -0
  38. data/lib/advert_selector/version.rb +3 -0
  39. data/lib/tasks/advert_selector_tasks.rake +4 -0
  40. data/test/advert_selector_test.rb +7 -0
  41. data/test/dummy/README.rdoc +261 -0
  42. data/test/dummy/Rakefile +7 -0
  43. data/test/dummy/app/assets/javascripts/application.js +15 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  46. data/test/dummy/app/controllers/application_controller.rb +4 -0
  47. data/test/dummy/app/controllers/examples_controller.rb +4 -0
  48. data/test/dummy/app/helpers/advert_selector_helper.rb +23 -0
  49. data/test/dummy/app/helpers/application_helper.rb +2 -0
  50. data/test/dummy/app/views/examples/index.html.erb +34 -0
  51. data/test/dummy/app/views/layouts/application.html.erb +20 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/config/application.rb +59 -0
  54. data/test/dummy/config/boot.rb +10 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +37 -0
  58. data/test/dummy/config/environments/production.rb +67 -0
  59. data/test/dummy/config/environments/test.rb +37 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/inflections.rb +15 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +7 -0
  64. data/test/dummy/config/initializers/session_store.rb +8 -0
  65. data/test/dummy/config/initializers/silence_assets.rb +20 -0
  66. data/test/dummy/config/initializers/simple_form.rb +178 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +5 -0
  69. data/test/dummy/config/locales/simple_form.en.yml +26 -0
  70. data/test/dummy/config/routes.rb +8 -0
  71. data/test/dummy/db/development.sqlite3 +0 -0
  72. data/test/dummy/db/migrate/20120928114159_create_advert_selector_placements.advert_selector.rb +12 -0
  73. data/test/dummy/db/migrate/20120928114160_create_advert_selector_banners.advert_selector.rb +24 -0
  74. data/test/dummy/db/migrate/20120928114161_create_advert_selector_helper_items.advert_selector.rb +19 -0
  75. data/test/dummy/db/schema.rb +53 -0
  76. data/test/dummy/db/test.sqlite3 +0 -0
  77. data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  78. data/test/dummy/log/development.log +11516 -0
  79. data/test/dummy/log/test.log +66467 -0
  80. data/test/dummy/public/404.html +26 -0
  81. data/test/dummy/public/422.html +26 -0
  82. data/test/dummy/public/500.html +25 -0
  83. data/test/dummy/public/favicon.ico +0 -0
  84. data/test/dummy/script/rails +6 -0
  85. data/test/dummy/test/unit/helpers/examples_helper_test.rb +4 -0
  86. data/test/dummy/tmp/cache/88F/B60/AdvertSelectorBanner_2 +0 -0
  87. data/test/dummy/tmp/cache/943/570/advert_selector_errors +0 -0
  88. data/test/dummy/tmp/cache/A2C/760/AdvertSelectorBanner_207249520 +0 -0
  89. data/test/dummy/tmp/cache/A3E/CF0/AdvertSelectorBanner_394627963 +0 -0
  90. data/test/dummy/tmp/cache/A3F/BF0/AdvertSelectorBanner_814558298 +0 -0
  91. data/test/dummy/tmp/cache/A40/C00/AdvertSelectorBanner_814558299 +0 -0
  92. data/test/dummy/tmp/cache/assets/C57/D40/sprockets%2F4f1a95218761045e0b23975e889644aa +0 -0
  93. data/test/dummy/tmp/cache/assets/C5F/E80/sprockets%2F01c5361554f26407988a43647d88c5fe +0 -0
  94. data/test/dummy/tmp/cache/assets/C75/2E0/sprockets%2F23135a6eb5317973d290438c359a3c0a +0 -0
  95. data/test/dummy/tmp/cache/assets/C77/A40/sprockets%2F3b3d6c1426796a7024c7d3f42c283026 +0 -0
  96. data/test/dummy/tmp/cache/assets/C86/C20/sprockets%2Ffe1477ea429411b3b581466c928b6860 +0 -0
  97. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  98. data/test/dummy/tmp/cache/assets/CBA/C70/sprockets%2F26288ca60ed05d24b8189328e4df9373 +0 -0
  99. data/test/dummy/tmp/cache/assets/CD1/A90/sprockets%2F433a791e2f93c0d8391aaa62203943ca +0 -0
  100. data/test/dummy/tmp/cache/assets/CD3/DE0/sprockets%2F0406286714c3c0abfcb4573336f7e33c +0 -0
  101. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  102. data/test/dummy/tmp/cache/assets/CD9/E80/sprockets%2F9052578aacc61253aa3854fa03b4895d +0 -0
  103. data/test/dummy/tmp/cache/assets/CEB/040/sprockets%2F644677c3bb57b6ed6b675229cfe54305 +0 -0
  104. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  105. data/test/dummy/tmp/cache/assets/CF2/EF0/sprockets%2F30ffd128655c9f04e88fba233248e997 +0 -0
  106. data/test/dummy/tmp/cache/assets/CF7/B60/sprockets%2F2c2a2af94201088a2a815ba90b8d344c +0 -0
  107. data/test/dummy/tmp/cache/assets/D05/4D0/sprockets%2F2d14560f81284bfb61fc0e187a803f1d +0 -0
  108. data/test/dummy/tmp/cache/assets/D0E/380/sprockets%2Ff27b6f5008c5a7324a7d8a382f21e7f2 +0 -0
  109. data/test/dummy/tmp/cache/assets/D19/820/sprockets%2Fccd0e907b49615494cc88c43a4781a9c +0 -0
  110. data/test/dummy/tmp/cache/assets/D28/910/sprockets%2F79b8a6fa551206c9996cfe98b80492cb +0 -0
  111. data/test/dummy/tmp/cache/assets/D2D/C20/sprockets%2Ff7d7fd5892b198e1588dd7d90a29a717 +0 -0
  112. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  113. data/test/dummy/tmp/cache/assets/D36/570/sprockets%2Fadfccb7c2436e006496eae16d6901523 +0 -0
  114. data/test/dummy/tmp/cache/assets/D40/110/sprockets%2Fbc5fcd75a352287c59787234ccbb11a8 +0 -0
  115. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  116. data/test/dummy/tmp/cache/assets/D50/030/sprockets%2F90296cd1ff74af449206b4fbd57cc995 +0 -0
  117. data/test/dummy/tmp/cache/assets/D50/BD0/sprockets%2F9c4832ce629b45b57ed8a55fbc717a86 +0 -0
  118. data/test/dummy/tmp/cache/assets/D55/240/sprockets%2F4b378a9f8c71e387569adfd712a26ce9 +0 -0
  119. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  120. data/test/dummy/tmp/cache/assets/D68/0A0/sprockets%2F17a08f579f5d1585bbd0c6ce2bac4351 +0 -0
  121. data/test/dummy/tmp/cache/assets/D68/220/sprockets%2F701db0b265a7c593768caebb904de9a1 +0 -0
  122. data/test/dummy/tmp/cache/assets/D6A/EF0/sprockets%2F2eb65cc490ad96cc38604918b0caeb90 +0 -0
  123. data/test/dummy/tmp/cache/assets/D6F/040/sprockets%2Fbd56a4cbc86673dbf2242fb85571bf61 +0 -0
  124. data/test/dummy/tmp/cache/assets/D70/540/sprockets%2Ffb1dbed4c6b15bc994454964bd455a43 +0 -0
  125. data/test/dummy/tmp/cache/assets/D83/400/sprockets%2Fc5adb5e35a83a7e10361f02afa42d4c1 +0 -0
  126. data/test/dummy/tmp/cache/assets/D88/7F0/sprockets%2Fe3b83e01d5f51e442ec9c11b40cca81a +0 -0
  127. data/test/dummy/tmp/cache/assets/DA3/080/sprockets%2Ffb77a66783db0b5812e3fdbabe4608f6 +0 -0
  128. data/test/dummy/tmp/cache/assets/DCE/810/sprockets%2F6eeb2d90a03c9de3ce8f5f30acf58118 +0 -0
  129. data/test/dummy/tmp/cache/assets/DCE/D50/sprockets%2F2232ec55b4deca5e8120ced9bd79ef54 +0 -0
  130. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  131. data/test/dummy/tmp/cache/assets/DF1/360/sprockets%2F23acf8b0d41e15db4d6ac2729f3eed1d +0 -0
  132. data/test/dummy/tmp/cache/assets/DF5/B00/sprockets%2Ff93edea94ff32d205acd8cdc4532b12b +0 -0
  133. data/test/dummy/tmp/cache/assets/DFB/9A0/sprockets%2Fb9a29f57d1ebf045452ed6cbd62eae1d +0 -0
  134. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  135. data/test/dummy/tmp/cache/assets/E53/3C0/sprockets%2Fcd0f7cae0b53d5ff22db8bf547d6a1bc +0 -0
  136. data/test/fixtures/advert_selector/banners.yml +38 -0
  137. data/test/fixtures/advert_selector/helper_items.yml +28 -0
  138. data/test/fixtures/advert_selector/placements.yml +17 -0
  139. data/test/functional/advert_selector/banners_controller_test.rb +64 -0
  140. data/test/functional/advert_selector/main_controller_test.rb +30 -0
  141. data/test/functional/advert_selector/placements_controller_test.rb +58 -0
  142. data/test/functional/examples_controller_test.rb +13 -0
  143. data/test/integration/banner_shows_test.rb +154 -0
  144. data/test/integration/navigation_test.rb +10 -0
  145. data/test/test_helper.rb +43 -0
  146. data/test/unit/advert_selector/banner_test.rb +160 -0
  147. data/test/unit/advert_selector/helper_item_test.rb +9 -0
  148. data/test/unit/advert_selector/placement_test.rb +50 -0
  149. data/test/unit/helpers/advert_selector/banners_helper_test.rb +6 -0
  150. data/test/unit/helpers/advert_selector/placements_helper_test.rb +6 -0
  151. metadata +425 -0
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,132 @@
1
+ # AdvertSelector
2
+
3
+ Rails adserver tool for selecting a smaller subset of banners from all
4
+ possible banners with differing banner placement combinations. Gem
5
+ includes admin tools for handling banners in live
6
+ environment. Includes basic targeting, viewcount, frequency etc
7
+ setups.
8
+
9
+ Good for deciding e.g. what height of header banner you will have
10
+ during the initial requests without extra javascript calls to
11
+ adserver. This helps to avoid problems of browser not knowing what
12
+ size of banner there is and enables browser to render the whole page
13
+ faster.
14
+
15
+ [<img src="https://secure.travis-ci.org/holli/advert_selector.png" />](http://travis-ci.org/holli/advert_selector)
16
+
17
+ ## Features
18
+
19
+ - selecting small subset of (advert) banners from multiple banners
20
+ - banners can be also be any kind of widgets
21
+ - defining banners
22
+ - setting filters to banners in a rails friendly way
23
+ - defining placements
24
+ - setting conflicting placements
25
+ - setting filters for placements
26
+ - admin tools
27
+ - editing everything
28
+ - testing banners before setting it to live env
29
+ - showing information in banner testing
30
+ - showing error log if there is a problem in banner filters
31
+
32
+ ## Install
33
+
34
+ ```
35
+ in /gemfile
36
+ gem 'advert_selector'
37
+
38
+ # Run following
39
+ # bundle
40
+ # bundle exec rake railties:install:migrations
41
+ # rake db:migrate
42
+
43
+ in top of views/layouts/your_layout
44
+ <% advert_selector_initialize(:all) %>
45
+ and if you want testing info then at the bottom
46
+ <%= advert_selector_force_test_infos %>
47
+
48
+ set to somewhere in your layout e.g.
49
+ <%= content_for :banner_header %>
50
+
51
+ in config/routes
52
+ mount AdvertSelector::Engine => "/advert_selector"
53
+
54
+ test the admin tool in url
55
+ http://localhost:3000/advert_selector/
56
+
57
+ ```
58
+
59
+ ## Configuration
60
+
61
+
62
+ ```
63
+ set extra_configuration in /config/initializers/advert_selector.rb
64
+
65
+
66
+ AdvertSelector.default_banner_test_url = "http://yourdomain.com/?"
67
+ self.default_time_zone = 'Helsinki'
68
+
69
+ class AdminAccessToGemTools
70
+ def self.admin_access(controller)
71
+ if !controller.session[:admin_logged].blank? || Rails.env.development?
72
+ return true
73
+ else
74
+ return false
75
+ end
76
+ end
77
+ end
78
+ AdvertSelector.admin_access_class = AdminAccessToGemTools
79
+
80
+
81
+ ```
82
+
83
+
84
+ ## Trageting / Content / HelperItem
85
+
86
+ All contents and targetings are done through HelperItem-model.
87
+
88
+ ### For targeting define custom helpers alongside your normal viewhelpers. Start by name advert_selector. E.g
89
+
90
+ ```
91
+ module AdvertSelectorHelper
92
+ def advert_selector_targeting_gender?(helper_item)
93
+ params[:gender] == helper_item.content
94
+ end
95
+ end
96
+
97
+ And in banner define HelperItem with name 'targeting_age?' and content 'male'. After that the banner would be shown only with
98
+ requests that has param[:gender]='male'.
99
+
100
+ ```
101
+
102
+ ### For displaying banner content
103
+
104
+ HelperItems that are tagged with content_for are used with content_for method in rails. E.g. HelperItem.name = :banner_header
105
+ and then in your views you display results by <%= content_for :banner_header %>
106
+
107
+ ## Inside
108
+
109
+ Banners are read to ruby processes memory once every 10 minutes from sql database.
110
+ Gem uses Rails.cache to cache viewcount of banners. Viewcount is updated to db once in a while.
111
+
112
+ Remember that this is not the real viewcount that more advanced banner handling systems have. Bots e.g. will increase the viewcount number
113
+
114
+
115
+ ## Some links you might also consider
116
+
117
+ - http://www.openx.com/
118
+ - http://www.google.com/dfp/info/sb/index.html
119
+
120
+ ## Requirements
121
+
122
+ Gem has been tested with ruby 1.8.7, 1.9.2 and Rails 3.2.
123
+
124
+ [<img src="https://secure.travis-ci.org/holli/advert_selector.png" />](http://travis-ci.org/holli/advert_selector)
125
+
126
+ ## Support
127
+
128
+ Submit suggestions or feature requests as a GitHub Issue or Pull Request. Remember to update tests. Tests are quite extensive.
129
+
130
+ ## Licence
131
+
132
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AdvertSelector'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ // = require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,29 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
14
+
15
+
16
+
17
+ body {
18
+ padding-top: 60px;
19
+ padding-bottom: 40px;
20
+ }
21
+ .sidebar-nav {
22
+ padding: 9px 0;
23
+ }
24
+
25
+ .form-horizontal .control-group { margin-bottom: 10px; }
26
+
27
+ label, input, button, select, textarea { font-size: 12px !important; }
28
+
29
+
@@ -0,0 +1,26 @@
1
+ module AdvertSelector
2
+ class ApplicationController < ActionController::Base
3
+
4
+ before_filter :admin_access_only
5
+ before_filter :set_time_zone
6
+ before_filter :set_locale
7
+
8
+ def admin_access_only
9
+ if AdvertSelector.admin_access_class.send(:admin_access, self)
10
+ return true
11
+ else
12
+ render :text => "Forbidden, only for admins", :status => 403
13
+ return false
14
+ end
15
+ end
16
+
17
+ def set_time_zone
18
+ Time.zone = AdvertSelector.default_time_zone
19
+ end
20
+
21
+ def set_locale
22
+ I18n.locale = :en
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,122 @@
1
+ require_dependency "advert_selector/application_controller"
2
+
3
+ module AdvertSelector
4
+ class BannersController < ApplicationController
5
+ # GET /banners
6
+ # GET /banners.json
7
+ def index
8
+ @banners = Banner.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render :json => @banners }
13
+ end
14
+ end
15
+
16
+ # GET /banners/1
17
+ # GET /banners/1.json
18
+ def show
19
+ redirect_to edit_banner_url(params[:id])
20
+
21
+ #@banner = Banner.find(params[:id])
22
+ #
23
+ #respond_to do |format|
24
+ # format.html # show.html.erb
25
+ # format.json { render :json => @banner }
26
+ #end
27
+ end
28
+
29
+ # GET /banners/new
30
+ # GET /banners/new.json
31
+ def new
32
+ if params[:duplicate_id] && banner_dup = Banner.find_by_id(params[:duplicate_id])
33
+ @banner = banner_dup.dup
34
+ @banner.name += " (copy)"
35
+ @banner.confirmed = false
36
+
37
+ banner_dup.helper_items.each do |hi|
38
+ @banner.helper_items << hi.dup
39
+ end
40
+
41
+ else
42
+ @banner = Banner.new
43
+ @banner.start_time = Time.now.at_midnight
44
+ @banner.end_time = 1.week.from_now.end_of_day
45
+ end
46
+
47
+ respond_to do |format|
48
+ format.html # new.html.erb
49
+ format.json { render :json => @banner }
50
+ end
51
+ end
52
+
53
+ # GET /banners/1/edit
54
+ def edit
55
+ @banner = Banner.find(params[:id])
56
+ end
57
+
58
+ # POST /banners
59
+ # POST /banners.json
60
+ def create
61
+ @banner = Banner.new(params[:banner])
62
+
63
+ respond_to do |format|
64
+ if @banner.save
65
+ format.html { redirect_to @banner, :notice => 'Banner was successfully created.' }
66
+ format.json { render :json => @banner, :status => :created, :location => @banner }
67
+ else
68
+ format.html { render :action => "new" }
69
+ format.json { render :json => @banner.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # PUT /banners/1
75
+ # PUT /banners/1.json
76
+ def update
77
+ @banner = Banner.find(params[:id])
78
+
79
+ respond_to do |format|
80
+ if @banner.update_attributes(params[:banner])
81
+ format.html { redirect_to @banner, :notice => 'Banner was successfully updated.' }
82
+ format.json { head :no_content }
83
+ else
84
+ format.html { render :action => "edit" }
85
+ format.json { render :json => @banner.errors, :status => :unprocessable_entity }
86
+ end
87
+ end
88
+ end
89
+
90
+
91
+ def update_running_view_count
92
+ @banner = Banner.find(params[:id])
93
+ if !(@count = params['banner']["running_view_count"]).blank?
94
+ @count = @count.to_i
95
+ Banner.where(:id => @banner.id).update_all(:running_view_count => @count)
96
+ 50.times do
97
+ # We are trying to make sure that no other process will overwrite this value
98
+ Rails.cache.write(@banner.cache_key, @count, :expires_in => 2.weeks)
99
+ sleep(0.02)
100
+ end
101
+ Banner.where(:id => @banner.id).update_all(:running_view_count => @count)
102
+ #@banner[:running_view_count] = @count
103
+ #@banner.save
104
+ end
105
+
106
+ redirect_to @banner
107
+ end
108
+
109
+ # DELETE /banners/1
110
+ # DELETE /banners/1.json
111
+ def destroy
112
+ @banner = Banner.find(params[:id])
113
+ @banner.destroy
114
+
115
+ respond_to do |format|
116
+ format.html { redirect_to banners_url }
117
+ format.json { head :no_content }
118
+ end
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "advert_selector/application_controller"
2
+
3
+ module AdvertSelector
4
+ class MainController < ApplicationController
5
+ def index
6
+ end
7
+
8
+ def clear_errors_log
9
+ AdvertSelector::ErrorsCache.clear
10
+ redirect_to :action => :index
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,89 @@
1
+ require_dependency "advert_selector/application_controller"
2
+
3
+ module AdvertSelector
4
+ class PlacementsController < ApplicationController
5
+ # GET /placements
6
+ # GET /placements.json
7
+ def index
8
+ @placements = Placement.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render :json => @placements }
13
+ end
14
+ end
15
+
16
+ # GET /placements/1
17
+ # GET /placements/1.json
18
+ def show
19
+ redirect_to edit_placement_url(params[:id])
20
+
21
+ #@placement = Placement.find(params[:id])
22
+ #
23
+ #respond_to do |format|
24
+ # format.html # show.html.erb
25
+ # format.json { render :json => @placement }
26
+ #end
27
+ end
28
+
29
+ # GET /placements/new
30
+ # GET /placements/new.json
31
+ def new
32
+ @placement = Placement.new
33
+
34
+ respond_to do |format|
35
+ format.html # new.html.erb
36
+ format.json { render :json => @placement }
37
+ end
38
+ end
39
+
40
+ # GET /placements/1/edit
41
+ def edit
42
+ @placement = Placement.find(params[:id])
43
+ end
44
+
45
+ # POST /placements
46
+ # POST /placements.json
47
+ def create
48
+ @placement = Placement.new(params[:placement])
49
+
50
+ respond_to do |format|
51
+ if @placement.save
52
+ format.html { redirect_to @placement, :notice => 'Placement was successfully created.' }
53
+ format.json { render :json => @placement, :status => :created, :location => @placement }
54
+ else
55
+ format.html { render :action => "new" }
56
+ format.json { render :json => @placement.errors, :status => :unprocessable_entity }
57
+ end
58
+ end
59
+ end
60
+
61
+ # PUT /placements/1
62
+ # PUT /placements/1.json
63
+ def update
64
+ @placement = Placement.find(params[:id])
65
+
66
+ respond_to do |format|
67
+ if @placement.update_attributes(params[:placement])
68
+ format.html { redirect_to @placement, :notice => 'Placement was successfully updated.' }
69
+ format.json { head :no_content }
70
+ else
71
+ format.html { render :action => "edit" }
72
+ format.json { render :json => @placement.errors, :status => :unprocessable_entity }
73
+ end
74
+ end
75
+ end
76
+
77
+ # DELETE /placements/1
78
+ # DELETE /placements/1.json
79
+ def destroy
80
+ @placement = Placement.find(params[:id])
81
+ @placement.destroy
82
+
83
+ respond_to do |format|
84
+ format.html { redirect_to placements_url }
85
+ format.json { head :no_content }
86
+ end
87
+ end
88
+ end
89
+ end