tb_banners 1.2.0.beta1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/README.markdown +9 -14
  3. data/Rakefile +2 -5
  4. data/app/assets/javascripts/admin/banners/banner_sets.js +4 -1
  5. data/app/assets/javascripts/admin/banners/banners.js +49 -56
  6. data/app/assets/stylesheets/admin/banners/banners.css.scss +6 -1
  7. data/app/controllers/admin/banner_sets_controller.rb +15 -23
  8. data/app/controllers/admin/banners_controller.rb +32 -61
  9. data/app/helpers/spud_banners_helper.rb +24 -19
  10. data/app/models/spud_banner.rb +33 -20
  11. data/app/models/spud_banner_set.rb +16 -19
  12. data/app/views/admin/banner_sets/index.html.erb +1 -1
  13. data/app/views/admin/banner_sets/show.html.erb +2 -1
  14. data/app/views/admin/banners/_banner.html.erb +4 -1
  15. data/app/views/admin/banners/_form.html.erb +3 -5
  16. data/db/migrate/20121116195139_create_spud_banners.rb +1 -1
  17. data/db/migrate/20121116195312_create_spud_banner_sets.rb +1 -1
  18. data/db/migrate/20130614132846_add_rich_text_to_spud_banners.rb +1 -1
  19. data/db/migrate/20140721142719_add_start_and_end_dates_to_spud_banners.rb +1 -1
  20. data/lib/spud_banners/configuration.rb +6 -5
  21. data/lib/spud_banners/engine.rb +13 -11
  22. data/lib/spud_banners/version.rb +1 -1
  23. data/lib/tb_banners.rb +1 -2
  24. data/spec/controllers/admin/banner_sets_controller_spec.rb +57 -58
  25. data/spec/dummy/config.ru +1 -1
  26. data/spec/dummy/config/application.rb +2 -3
  27. data/spec/dummy/config/boot.rb +1 -1
  28. data/spec/dummy/config/environments/production.rb +1 -1
  29. data/spec/dummy/config/environments/test.rb +3 -4
  30. data/spec/dummy/config/initializers/secret_token.rb +0 -1
  31. data/spec/dummy/db/migrate/20121127192246_create_spud_admin_permissions.spud_core.rb +1 -1
  32. data/spec/dummy/db/migrate/20121127192247_create_spud_users.spud_core.rb +13 -13
  33. data/spec/dummy/db/migrate/20121127192248_add_time_zone_to_spud_user.spud_core.rb +1 -2
  34. data/spec/dummy/db/migrate/20121127192249_add_scope_to_spud_admin_permissions.spud_core.rb +1 -2
  35. data/spec/dummy/db/migrate/20121127192250_create_spud_user_settings.spud_core.rb +1 -1
  36. data/spec/dummy/db/migrate/20130920154442_create_spud_roles.tb_core.rb +1 -1
  37. data/spec/dummy/db/migrate/20130920154443_create_spud_permissions.tb_core.rb +4 -4
  38. data/spec/dummy/db/migrate/20130920154444_create_spud_role_permissions.tb_core.rb +3 -3
  39. data/spec/dummy/db/migrate/20130920154445_drop_spud_admin_permissions.tb_core.rb +1 -1
  40. data/spec/dummy/db/migrate/20160310164644_add_requires_password_change_to_spud_users.tb_core.rb +6 -0
  41. data/spec/dummy/db/schema.rb +70 -84
  42. data/spec/dummy/script/rails +2 -2
  43. data/spec/factories/spud_banner_sets.rb +9 -0
  44. data/spec/factories/spud_banners.rb +7 -0
  45. data/spec/models/spud_banner_spec.rb +27 -0
  46. data/spec/rails_helper.rb +81 -0
  47. data/spec/spec_helper.rb +77 -34
  48. metadata +79 -109
  49. data/app/views/admin/banners/legacy.js.erb +0 -5
  50. data/lib/spud_banners/liquid_tags.rb +0 -31
  51. data/spec/dummy/db/migrate/20130920154446_create_spud_banners.tb_banners.rb +0 -16
  52. data/spec/dummy/db/migrate/20130920154447_create_spud_banner_sets.tb_banners.rb +0 -13
  53. data/spec/dummy/db/migrate/20130920154448_add_rich_text_to_spud_banners.tb_banners.rb +0 -7
  54. data/spec/dummy/db/migrate/20140120174546_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +0 -13
  55. data/spec/support/authlogic_helper.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 77d69497d933e4e7d8b92513aef1b785d67fdee0
4
- data.tar.gz: 379864ece8c927552575a6bda6b161172492a805
2
+ SHA256:
3
+ metadata.gz: c6523446637e03b2e8bbf0817e9a3f932a914ec2eb4e9b15564a5e41d5e1f4b8
4
+ data.tar.gz: 96800f6ab2b718017ec48b39d4f403a59682b7cca43c45e7b271972d35582335
5
5
  SHA512:
6
- metadata.gz: d4c75394cc35e6c9e43816f31fe477a9ed2047cc20f77193d47fbf8ed7cf0189939e72199cc6a09f35a79221ee6929f155d04d8beb8b3eee0adc5ff112d273cc
7
- data.tar.gz: 123e7574293cf224312fa1b5e080b73a0f18fe1914ad1991e1b57c3556f9e5509d9c78b4901df271278fc81111b4a73f0324b496031dd94db216cd9f5cd31b4d
6
+ metadata.gz: 9a832b4f51efcbb3904b77b2b29be04a89d4e07ad4c242e46de3427d81abd268f538d5a588ff3bba4a1402072a06d71936074177f7da3b7cca171329f4c1e1a2
7
+ data.tar.gz: ae6b66441337ca85a0e91b998f77871b72ce6c47c2ff16d1f5215ae487c55559316dbf29e17e0b723951c2e28dd44258ae476f951a7725f6f6f12e716a9852f1
@@ -24,6 +24,7 @@ TB Banners accepts the following configuration options:
24
24
  Spud::Banners.configure do |config|
25
25
  config.paperclip_storage = :filesystem #use :s3 to use s3 storage (aws gem required)
26
26
  config.s3_credentials = "#{Rails.root}/config/s3.yml"
27
+ config.s3_protocol = 'https'
27
28
  config.storage_path = ":rails_root/public/system/spud_banners/:id/:style/:basename.:extension"
28
29
  config.storage_url = "/system/spud_banners/:id/:style/:basename.:extension"
29
30
  end
@@ -48,7 +49,12 @@ A number of view helpers are provided for displaying banners in your templates.
48
49
 
49
50
  `spud_banners_for_set(set_or_identifier, options)`
50
51
 
51
- Accepts the banner set name as a String or Symbol and returns an html template. Options hash accepts a `:limit` parameter for limiting the number of banners returned. This helper also accepts a block argument for rendering custom html.
52
+ Accepts the banner set name as a String or Symbol and returns an html template. This helper also accepts a block argument for rendering custom html.
53
+
54
+ **Options:**
55
+
56
+ - `limit`: Limit how many banners you wish to render
57
+ - `background_image`: Pass `true` in order to render the banners as divs with css background images instead of image tags. Defaults to `false`. **This is required when rendering banners with rich text.**
52
58
 
53
59
  ```ruby
54
60
  spud_banner_tag(banner)
@@ -97,21 +103,11 @@ Displaying banners using the helper, with a block for even more custom html.
97
103
  </ul>
98
104
  ```
99
105
 
100
- ## Liquid
101
-
102
- TB Banners comes with its own custom [Liquid][liquid] tag. For now the liquid tag only supports rendering the standard html as generated by the `spud_banners_for_set`. Will provide support more advanced options in the future.
103
-
104
- Usage:
105
-
106
- ```erb
107
- <%= raw Liquid::Template.parse("{% spud_banner_set Promotions %}").render %>
108
- ```
109
-
110
106
  ## Rich Text
111
107
 
112
- Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
108
+ Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
113
109
 
114
- Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
110
+ Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
115
111
 
116
112
  ```erb
117
113
  <ul id="slides">
@@ -160,4 +156,3 @@ Below is an example of integration with [SlidesJs][slidesjs], a jQuery plugin.
160
156
 
161
157
  [tb]:https://bitbucket.org/westlakedesign/tb_core
162
158
  [slidesjs]:http://www.slidesjs.com
163
- [liquid]:https://github.com/Shopify/liquid
data/Rakefile CHANGED
@@ -20,11 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
23
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
-
27
-
28
26
  Bundler::GemHelper.install_tasks
29
27
 
30
28
  require 'rake/testtask'
@@ -36,5 +34,4 @@ Rake::TestTask.new(:test) do |t|
36
34
  t.verbose = false
37
35
  end
38
36
 
39
-
40
- task :default => :test
37
+ task default: :test
@@ -5,7 +5,7 @@
5
5
 
6
6
  var bannerSetEditId = false;
7
7
 
8
- spud.admin.banner_sets = {
8
+ tb.banner_sets = {
9
9
  init: function(){
10
10
  $('.spud_banner_sets_add_new').on('click', clickedAddNewBannerSet);
11
11
  $('.admin-banner-sets-list').on('click', '.admin-banner-set-edit', clickedEditBannerSet);
@@ -46,6 +46,9 @@ var clickedEditBannerSet = function(e){
46
46
 
47
47
  var clickedDeleteBannerSet = function(e){
48
48
  e.preventDefault();
49
+ $.ajaxSetup({
50
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
51
+ });
49
52
  if(window.confirm('Are you sure?')){
50
53
  var el = $(this);
51
54
  $.ajax({
@@ -3,39 +3,29 @@
3
3
 
4
4
  (function(){
5
5
 
6
- var html5upload = false;
7
6
  var bannerEditId = false;
8
7
 
9
- spud.admin.banners = {
8
+ tb.banners = {
10
9
 
11
10
  // Index Page
12
11
  /////////////
13
12
  init: function(){
14
- if(typeof(FormData) != 'undefined'){
15
- html5upload = true;
16
- }
17
13
  $('.admin-banner-set-item-add').on('click', clickedAddNewBanner);
18
14
  $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-edit', clickedEditBanner);
19
15
  $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-delete', clickedDeleteBanner);
20
16
  $('.modal-body').on('submit', '.admin-banner-form', submittedBannerForm);
21
- $('.admin-banner-set-items-container').sortable({
22
- stop: sortedBanners,
23
- helper: fixHelper
17
+ Sortable.create(document.querySelector('.admin-banner-set-items-container'), {
18
+ onUpdate: sortedBanners,
19
+ dragClass: 'banner-dragging',
20
+ handle: '.glyphicon-sort'
24
21
  });
25
22
  }
26
23
  };
27
24
 
28
- // http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/
29
- var fixHelper = function(e, ui) {
30
- ui.children().each(function() {
31
- $(this).width($(this).width());
32
- });
33
- return ui;
34
- };
35
-
36
25
  var clickedAddNewBanner = function(e){
37
26
  e.preventDefault();
38
27
  bannerEditId = false;
28
+ spud.admin.editor.unload();
39
29
  $.ajax({
40
30
  url: $(this).attr('href'),
41
31
  dataType: 'html',
@@ -51,8 +41,8 @@ var clickedAddNewBanner = function(e){
51
41
 
52
42
  var clickedEditBanner = function(e){
53
43
  e.preventDefault();
54
- spud.admin.editor.unload();
55
44
  bannerEditId = parseInt($(this).parents('.admin-banner-set-item').attr('data-id'), 10);
45
+ spud.admin.editor.unload();
56
46
  $.ajax({
57
47
  url: $(this).attr('href'),
58
48
  dataType: 'html',
@@ -68,6 +58,9 @@ var clickedEditBanner = function(e){
68
58
 
69
59
  var clickedDeleteBanner = function(e){
70
60
  e.preventDefault();
61
+ $.ajaxSetup({
62
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
63
+ });
71
64
  var el = $(this);
72
65
  $.ajax({
73
66
  url: el.attr('href'),
@@ -86,43 +79,41 @@ var clickedDeleteBanner = function(e){
86
79
  };
87
80
 
88
81
  var submittedBannerForm = function(e){
89
- if(html5upload){
90
- e.preventDefault();
82
+ e.preventDefault();
91
83
 
92
- var form = $(this);
93
- var fd = new FormData();
94
-
95
- $('input[type=text], input[type=hidden], select').each(function(index, element){
96
- var input = $(element);
97
- var name = input.attr('name');
98
- var value = input.val();
99
- fd.append(name, value);
100
- });
84
+ var form = $(this);
85
+ var fd = new FormData();
101
86
 
102
- var richText = form.find('.admin-banner-rich-text');
103
- if(richText.length > 0){
104
- fd.append('spud_banner[rich_text]', richText.val());
105
- }
106
- else{
107
- fd.append('spud_banner[rich_text]', '');
108
- }
87
+ $('input[type=text], input[type=hidden], select').each(function(index, element){
88
+ var input = $(element);
89
+ var name = input.attr('name');
90
+ var value = input.val();
91
+ fd.append(name, value);
92
+ });
109
93
 
110
- var file = form.find('#spud_banner_banner')[0].files[0];
111
- if(file){
112
- fd.append('spud_banner[banner]', file);
113
- $('.admin-banner-upload-progress').show();
114
- }
94
+ var editor = tinymce.get('admin-banner-rich-text');
95
+ if(editor){
96
+ fd.append('spud_banner[rich_text]', editor.getContent());
97
+ }
98
+ else{
99
+ fd.append('spud_banner[rich_text]', '');
100
+ }
115
101
 
116
- var xhr = new XMLHttpRequest();
117
- xhr.upload.addEventListener('progress', onFileUploadProgress);
118
- xhr.addEventListener('load', onFileUploadComplete);
119
- xhr.addEventListener('error', onFileUploadError);
120
- xhr.addEventListener('abort', onFileUploadAbort);
121
- xhr.open('POST', form.attr('action'));
122
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
123
- xhr.send(fd);
124
- return false;
102
+ var file = form.find('#spud_banner_banner')[0].files[0];
103
+ if(file){
104
+ fd.append('spud_banner[banner]', file);
105
+ $('.admin-banner-upload-progress').show();
125
106
  }
107
+
108
+ var xhr = new XMLHttpRequest();
109
+ xhr.upload.addEventListener('progress', onFileUploadProgress);
110
+ xhr.addEventListener('load', onFileUploadComplete);
111
+ xhr.addEventListener('error', onFileUploadError);
112
+ xhr.addEventListener('abort', onFileUploadAbort);
113
+ xhr.open('POST', form.attr('action'));
114
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
115
+ xhr.send(fd);
116
+ return false;
126
117
  };
127
118
 
128
119
  var onFileUploadProgress = function(e){
@@ -137,10 +128,10 @@ var onFileUploadProgress = function(e){
137
128
  var onFileUploadComplete = function(e){
138
129
  switch(this.status){
139
130
  case 200:
140
- spud.admin.banners.onLegacyUploadComplete(e.target.response);
131
+ onUploadComplete(e.target.response);
141
132
  break;
142
133
  case 422:
143
- spud.admin.banners.onLegacyUploadError(e.target.response);
134
+ onUploadError(e.target.response);
144
135
  break;
145
136
  default:
146
137
  window.alert("Whoops! Something has gone wrong.");
@@ -155,8 +146,7 @@ var onFileUploadAbort = function(e){
155
146
 
156
147
  };
157
148
 
158
- // Non-html5 upload
159
- spud.admin.banners.onLegacyUploadComplete = function(html){
149
+ var onUploadComplete = function(html){
160
150
  if(bannerEditId){
161
151
  var item = $('.admin-banner-set-item[data-id="'+bannerEditId+'"]');
162
152
  item.replaceWith(html);
@@ -167,7 +157,7 @@ spud.admin.banners.onLegacyUploadComplete = function(html){
167
157
  spud.admin.modal.hide();
168
158
  };
169
159
 
170
- spud.admin.banners.onLegacyUploadError = function(html){
160
+ var onUploadError = function(html){
171
161
  $('.admin-banner-form').replaceWith(html);
172
162
  initForm();
173
163
  };
@@ -178,16 +168,19 @@ var sortedBanners = function(e, ui){
178
168
  ids.push($(this).attr('data-id'));
179
169
  });
180
170
  $.ajax({
171
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() },
181
172
  url: '/admin/banners/sort',
182
173
  type: 'post',
183
- data: {spud_banner_ids:ids, _method:'put'}
174
+ data: { spud_banner_ids: ids, _method: 'put' }
184
175
  });
185
176
  };
186
177
 
187
178
  var initForm = function(){
188
179
  var richText = $('#admin-banner-rich-text');
189
180
  if(richText){
190
- tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'admin-banner-rich-text');
181
+ if(typeof tinymce != "undefined"){
182
+ tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'admin-banner-rich-text');
183
+ }
191
184
  spud.admin.editor.init({
192
185
  selector: '#admin-banner-rich-text',
193
186
  buttons: ['bold','italic','underline','formatselect','|','bullist','numlist','|','link','unlink','anchor', '|', 'code'],
@@ -2,7 +2,7 @@
2
2
  .admin-banner-set-items-container{
3
3
 
4
4
  }
5
- .admin-banner-set-item{
5
+ .admin-banner-set-item .glyphicon-sort{
6
6
  cursor: move;
7
7
  }
8
8
  .admin-banner-set-item.ui-sortable-helper{
@@ -12,6 +12,11 @@
12
12
  .admin-banner-set-item img{
13
13
  display: block;
14
14
  }
15
+ tr.banner-dragging {
16
+ display: block;
17
+ width: 300px;
18
+ height: 100px;
19
+ }
15
20
 
16
21
  // Banner Form
17
22
  .admin-banner-upload-progress{
@@ -1,18 +1,18 @@
1
1
  class Admin::BannerSetsController < Admin::ApplicationController
2
2
 
3
- before_filter :get_record, :only => [:show, :edit, :update, :destroy]
3
+ before_action :load_record, only: [:show, :edit, :update, :destroy]
4
4
  respond_to :html
5
- belongs_to_spud_app :banner_sets
5
+ belongs_to_app :banner_sets
6
6
  add_breadcrumb 'Banner Sets', :admin_banner_sets_path
7
7
  layout false
8
8
 
9
9
  def index
10
10
  @banner_sets = SpudBannerSet.all
11
- respond_with @banner_sets, :layout => 'admin/detail'
11
+ respond_with @banner_sets, layout: 'admin/detail'
12
12
  end
13
13
 
14
14
  def show
15
- respond_with @banner_set, :layout => 'admin/detail'
15
+ respond_with @banner_set, layout: 'admin/detail'
16
16
  end
17
17
 
18
18
  def new
@@ -23,10 +23,10 @@ class Admin::BannerSetsController < Admin::ApplicationController
23
23
  def create
24
24
  @banner_set = SpudBannerSet.new(banner_set_params)
25
25
  if @banner_set.save
26
- flash.now[:notice] = 'BannerSet created successfully'
26
+ flash.now[:notice] = 'Banner Set created successfully'
27
27
  render 'create'
28
28
  else
29
- render 'new', :status => 422
29
+ render 'new', status: :unprocessable_entity
30
30
  end
31
31
  end
32
32
 
@@ -35,35 +35,27 @@ class Admin::BannerSetsController < Admin::ApplicationController
35
35
  end
36
36
 
37
37
  def update
38
- if @banner_set.update_attributes(banner_set_params)
39
- flash.now[:notice] = 'BannerSet updated successfully'
38
+ if @banner_set.update(banner_set_params)
39
+ flash.now[:notice] = 'Banner Set updated successfully'
40
40
  render 'create'
41
41
  else
42
- render 'edit', :status => 422
42
+ render 'edit', status: :unprocessable_entity
43
43
  end
44
44
  end
45
45
 
46
46
  def destroy
47
- if @banner_set.destroy
48
- flash.now[:notice] = 'BannerSet deleted successfully'
49
- end
50
- render :nothing => true
47
+ flash.now[:notice] = 'Banner Set deleted successfully' if @banner_set.destroy
48
+ head :ok
51
49
  end
52
50
 
53
- private
51
+ private
54
52
 
55
- def get_record
56
- begin
57
- @banner_set = SpudBannerSet.find(params[:id])
58
- rescue ActiveRecord::RecordNotFound => e
59
- flash.now[:error] = "Could not find the requested BannerSet"
60
- redirect_to admin_banner_sets_path
61
- return false
62
- end
53
+ def load_record
54
+ @banner_set = SpudBannerSet.find_by!(id: params[:id])
63
55
  end
64
56
 
65
57
  def banner_set_params
66
58
  params.require(:spud_banner_set).permit(:cropped, :height, :name, :short_name, :width, :has_rich_text)
67
59
  end
68
60
 
69
- end
61
+ end
@@ -1,14 +1,12 @@
1
1
  class Admin::BannersController < Admin::ApplicationController
2
2
 
3
- include RespondsToParent
4
-
5
- before_filter :get_set, :only => [:new, :create]
6
- before_filter :get_record, :only => [:edit, :update, :destroy]
3
+ before_action :load_set, only: [:new, :create]
4
+ before_action :load_record, only: [:edit, :update, :destroy]
7
5
  respond_to :html
8
6
  layout false
9
7
 
10
8
  def new
11
- @banner = @banner_set.banners.new(:start_date => Date.today)
9
+ @banner = @banner_set.banners.new(start_date: Time.zone.today)
12
10
  respond_with @banner
13
11
  end
14
12
 
@@ -16,23 +14,16 @@ class Admin::BannersController < Admin::ApplicationController
16
14
  @banner = @banner_set.banners.build
17
15
  @banner.attributes = banner_params
18
16
 
19
- last_banner = SpudBanner.select('sort_order').where(:spud_banner_set_id => @banner_set.id).order('sort_order desc').first
20
- if last_banner
21
- @banner.sort_order = last_banner.sort_order + 1
22
- end
17
+ last_banner = SpudBanner.select(:sort_order)
18
+ .where(spud_banner_set_id: @banner_set.id)
19
+ .order(sort_order: :desc).first
20
+ @banner.sort_order = last_banner.sort_order + 1 if last_banner
23
21
 
24
- if request.xhr?
25
- if @banner.save
26
- flash.now[:notice] = 'SpudBanner created successfully'
27
- render 'show'
28
- else
29
- render 'new', :status => 422
30
- end
22
+ if @banner.save
23
+ flash.now[:notice] = 'Banner created successfully'
24
+ render 'show'
31
25
  else
32
- @banner.save
33
- respond_to_parent do
34
- render 'legacy', :formats => [:js]
35
- end
26
+ render 'new', status: :unprocessable_entity
36
27
  end
37
28
  end
38
29
 
@@ -41,68 +32,48 @@ class Admin::BannersController < Admin::ApplicationController
41
32
  end
42
33
 
43
34
  def update
44
- if request.xhr?
45
- if @banner.update_attributes(banner_params)
46
- flash.now[:notice] = 'SpudBanner created successfully'
47
- render 'show'
48
- else
49
- render 'edit', :status => 422
50
- end
35
+ if @banner.update(banner_params)
36
+ flash.now[:notice] = 'Banner created successfully'
37
+ render 'show'
51
38
  else
52
- @banner.update_attributes(banner_params)
53
- respond_to_parent do
54
- render 'legacy', :formats => [:js]
55
- end
39
+ render 'edit', status: :unprocessable_entity
56
40
  end
57
41
  end
58
42
 
59
43
  def destroy
60
- if @banner.destroy
61
- flash.now[:notice] = 'SpudBanner deleted successfully'
62
- status = 200
63
- else
64
- status = 422
65
- end
66
- render :nothing => true, :status => status
44
+ @banner.destroy
45
+ head :ok
67
46
  end
68
47
 
48
+ # rubocop:disable Rails/SkipsModelValidations
69
49
  def sort
70
50
  banner_ids = params[:spud_banner_ids]
71
- banners = SpudBanner.where(:id => banner_ids).to_a
51
+ banners = SpudBanner.where(id: banner_ids).to_a
72
52
  SpudBanner.transaction do
73
53
  banner_ids.each_with_index do |id, index|
74
- banner = banners.select{ |b| b.id == id.to_i }.first
54
+ banner = banners.select { |b| b.id == id.to_i }.first
75
55
  banner.update_column(:sort_order, index)
76
56
  end
77
- banners.last.owner.touch()
57
+ banners.last.owner.touch
78
58
  end
79
- render :nothing => true, :status => 200
59
+ head :ok
80
60
  end
61
+ # rubocop:enable Rails/SkipsModelValidations
81
62
 
82
- private
63
+ private
83
64
 
84
- def get_set
85
- begin
86
- @banner_set = SpudBannerSet.find(params[:banner_set_id])
87
- rescue ActiveRecord::RecordNotFound => e
88
- flash.now[:error] = "Could not find the requested SpudBannerSet"
89
- render :nothing => true, :status => 404
90
- return false
91
- end
65
+ def load_set
66
+ @banner_set = SpudBannerSet.find_by!(id: params[:banner_set_id])
92
67
  end
93
68
 
94
- def get_record
95
- begin
96
- @banner = SpudBanner.find(params[:id])
97
- rescue ActiveRecord::RecordNotFound => e
98
- flash.now[:error] = "Could not find the requested SpudBanner"
99
- redirect_to admin_banner_sets_path
100
- return false
101
- end
69
+ def load_record
70
+ @banner = SpudBanner.find_by!(id: params[:id])
102
71
  end
103
72
 
104
73
  def banner_params
105
- params.require(:spud_banner).permit(:banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date)
74
+ params.require(:spud_banner).permit(
75
+ :banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date
76
+ )
106
77
  end
107
78
 
108
- end
79
+ end