From 5e0488e021bee2002d70fa05b79bb85490af020b Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 7 Sep 2009 14:15:24 +0200 Subject: enabling featured articles --- app/helpers/content_helper.rb | 5 +++++ app/models/menu_item.rb | 26 ++++++++++++++++++++-- app/views/content/_featured_articles.html.erb | 9 ++++++++ app/views/content/_search.html.erb | 8 +++++++ app/views/layouts/application.html.erb | 12 ++++------ ...20090907103525_add_type_column_to_menu_items.rb | 9 ++++++++ .../20090907111533_add_type_id_to_menu_items.rb | 9 ++++++++ 7 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 app/views/content/_featured_articles.html.erb create mode 100644 app/views/content/_search.html.erb create mode 100644 db/migrate/20090907103525_add_type_column_to_menu_items.rb create mode 100644 db/migrate/20090907111533_add_type_id_to_menu_items.rb diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index d9ec5db..5a288ed 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -20,6 +20,11 @@ module ContentHelper render :partial => 'content/tags' end + def featured_articles + @featured_articles = FeaturedArticle.all + render :partial => 'content/featured_articles' + end + def headline_image image = @page.assets.images.first if image diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index e86be0e..054e7ee 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,6 +1,28 @@ class MenuItem < ActiveRecord::Base - translates :title + default_scope :conditions => {:type => "MenuItem"} - acts_as_list + translates :title + + acts_as_list :scope => :type + + before_save :determine_type_id + + + private + + def determine_type_id + case self.class.name + + when "MenuItem" + self.type_id = 1 + when "FeaturedArticle" + self.type_id = 2 + end + end end + + +class FeaturedArticle < MenuItem + default_scope :conditions => {:type => "FeaturedArticle"} +end \ No newline at end of file diff --git a/app/views/content/_featured_articles.html.erb b/app/views/content/_featured_articles.html.erb new file mode 100644 index 0000000..08f7624 --- /dev/null +++ b/app/views/content/_featured_articles.html.erb @@ -0,0 +1,9 @@ +
+

Featured

+ +
+ diff --git a/app/views/content/_search.html.erb b/app/views/content/_search.html.erb new file mode 100644 index 0000000..c6029e0 --- /dev/null +++ b/app/views/content/_search.html.erb @@ -0,0 +1,8 @@ + +<% form_tag search_path, :method => 'get' do %> + + + + +<% end %> +
<%= text_field_tag :search_term %><%= image_submit_tag("search_button.png") %>
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0b32673..7a5222d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,18 +15,13 @@ <%= image_tag "header.png" %>
<%= main_menu %> + <%= language_selector %> + <%= calendar %>
@@ -34,6 +29,7 @@
<%= tags %> + <%= featured_articles %>
diff --git a/db/migrate/20090907103525_add_type_column_to_menu_items.rb b/db/migrate/20090907103525_add_type_column_to_menu_items.rb new file mode 100644 index 0000000..dda0f9c --- /dev/null +++ b/db/migrate/20090907103525_add_type_column_to_menu_items.rb @@ -0,0 +1,9 @@ +class AddTypeColumnToMenuItems < ActiveRecord::Migration + def self.up + add_column :menu_items, :type, :string + end + + def self.down + remove_column :menu_items, :type + end +end diff --git a/db/migrate/20090907111533_add_type_id_to_menu_items.rb b/db/migrate/20090907111533_add_type_id_to_menu_items.rb new file mode 100644 index 0000000..5000e92 --- /dev/null +++ b/db/migrate/20090907111533_add_type_id_to_menu_items.rb @@ -0,0 +1,9 @@ +class AddTypeIdToMenuItems < ActiveRecord::Migration + def self.up + add_column :menu_items, :type_id, :integer + end + + def self.down + remove_column :menu_items, :type_id + end +end -- cgit v1.3