From 1277f7634650f9525d8ffea679c47a15833cbc87 Mon Sep 17 00:00:00 2001 From: Dries Steenhouwer Date: Thu, 5 Feb 2015 16:08:04 +0100 Subject: make homepage ready --- .../refinery/banners/admin/banners_controller.rb | 5 ++++ app/models/refinery/banners/banner.rb | 6 ++-- .../refinery/banners/admin/banners/_form.html.erb | 6 ++++ db/migrate/1_create_banners_banners.rb | 2 ++ lib/page_extensions.rb | 32 +++++++++++----------- refinerycms-pc_banners.gemspec | 4 +-- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/controllers/refinery/banners/admin/banners_controller.rb b/app/controllers/refinery/banners/admin/banners_controller.rb index 1992bcf..759476a 100644 --- a/app/controllers/refinery/banners/admin/banners_controller.rb +++ b/app/controllers/refinery/banners/admin/banners_controller.rb @@ -6,6 +6,11 @@ module Refinery crudify :'refinery/banners/banner', :title_attribute => 'name', :xhr_paging => true + private + def banner_params + params.require(:banner).permit! + end + end end end diff --git a/app/models/refinery/banners/banner.rb b/app/models/refinery/banners/banner.rb index 08b4b38..bccf63c 100644 --- a/app/models/refinery/banners/banner.rb +++ b/app/models/refinery/banners/banner.rb @@ -13,7 +13,7 @@ module Refinery validates_presence_of :start_date validates_length_of :title, :in => 0..255, :allow_nil => true validates_length_of :description, :in => 0..255, :allow_nil => true - + belongs_to :image, :class_name => '::Refinery::Image' has_and_belongs_to_many :pages, :class_name => '::Refinery::Page', :join_table => 'refinery_banners_pages' @@ -21,7 +21,7 @@ module Refinery banners = Arel::Table.new(::Refinery::Banners::Banner.table_name) where(banners[:expiry_date].eq(nil).or(banners[:expiry_date].gt(Time.now))) } - scope :active, where(:is_active => true) + scope :active, lambda { where(:is_active => true) } scope :published, lambda { not_expired.active.where("start_date <= ?", Time.now).order(:position) } @@ -29,6 +29,8 @@ module Refinery not_expired.active.where("start_date <= ?", Time.now).where("locale = ? or locale = ''", ::I18n.locale).order(:position) } + scope :in_category, ->(cat) { where(:category => cat)} + end end end \ No newline at end of file diff --git a/app/views/refinery/banners/admin/banners/_form.html.erb b/app/views/refinery/banners/admin/banners/_form.html.erb index 356719e..c4fbd21 100644 --- a/app/views/refinery/banners/admin/banners/_form.html.erb +++ b/app/views/refinery/banners/admin/banners/_form.html.erb @@ -41,6 +41,12 @@ +
+ <%= f.label :category -%> + <%= f.text_field :category -%> + +
+ <% if Refinery::I18n.frontend_locales %>
<%= f.label :locale -%> diff --git a/db/migrate/1_create_banners_banners.rb b/db/migrate/1_create_banners_banners.rb index f9e350a..f815020 100644 --- a/db/migrate/1_create_banners_banners.rb +++ b/db/migrate/1_create_banners_banners.rb @@ -11,6 +11,8 @@ class CreateBannersBanners < ActiveRecord::Migration t.date :start_date t.date :expiry_date t.integer :position + t.string :category + t.text :body t.timestamps end diff --git a/lib/page_extensions.rb b/lib/page_extensions.rb index d28c10c..973c177 100644 --- a/lib/page_extensions.rb +++ b/lib/page_extensions.rb @@ -1,17 +1,17 @@ -# module Refinery -# module Banners -# module Extensions -# module Page -# module ClassMethods -# def add_banners_relationship -# has_and_belongs_to_many :banners, :class_name => '::Refinery::Banners::Banner', :join_table => 'refinery_banners_pages' -# end -# end +module Refinery + module Banners + module Extensions + module Page + module ClassMethods + def add_banners_relationship + has_and_belongs_to_many :banners, :class_name => '::Refinery::Banners::Banner', :join_table => 'refinery_banners_pages' + end + end -# def self.included(base) -# base.extend(ClassMethods).add_banners_relationship -# end -# end -# end -# end -# end \ No newline at end of file + def self.included(base) + base.extend(ClassMethods).add_banners_relationship + end + end + end + end +end \ No newline at end of file diff --git a/refinerycms-pc_banners.gemspec b/refinerycms-pc_banners.gemspec index d7d0a66..ecc7881 100644 --- a/refinerycms-pc_banners.gemspec +++ b/refinerycms-pc_banners.gemspec @@ -14,8 +14,8 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/julesce/refinerycms-pods' # Runtime dependencies - s.add_dependency 'refinerycms-pages', '~> 3.0.0.dev' + s.add_dependency 'refinerycms-pages', '~> 3.0.0' # Development dependencies (usually used for testing) - s.add_development_dependency 'refinerycms-testing', '~> 3.0.0.dev' + s.add_development_dependency 'refinerycms-testing', '~> 3.0.0' end -- cgit v1.2.3