From 67448d4636769e318a490a25dacbedc410fb90d6 Mon Sep 17 00:00:00 2001 From: albert Date: Wed, 21 Dec 2011 18:41:17 -0500 Subject: [PATCH] automatically identify ad type --- app/logical/alias_and_implication_importer.rb | 2 +- app/models/advertisement.rb | 6 ++++++ app/views/advertisements/_form.html.erb | 5 ++--- app/views/advertisements/_secondary_links.html.erb | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index a1905ed62..ebf083494 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -55,7 +55,7 @@ private tag_implication = TagImplication.where("antecedent_name = ? and consequent_name = ?", token[1], token[2]).first raise "Implication for #{token[1]} not found" if tag_implication.nil? tag_implication.destroy - + else raise "Unknown token: #{token[0]}" end diff --git a/app/models/advertisement.rb b/app/models/advertisement.rb index 3a1af7428..b1198e0ce 100644 --- a/app/models/advertisement.rb +++ b/app/models/advertisement.rb @@ -50,6 +50,12 @@ class Advertisement < ActiveRecord::Base image_size = ImageSize.new(File.open(image_path, "rb")) self.width = image_size.get_width self.height = image_size.get_height + + if width > height + self.ad_type = "horizontal" + else + self.ad_type = "vertical" + end end end diff --git a/app/views/advertisements/_form.html.erb b/app/views/advertisements/_form.html.erb index 9745e32db..370cacc3c 100644 --- a/app/views/advertisements/_form.html.erb +++ b/app/views/advertisements/_form.html.erb @@ -1,7 +1,6 @@ <%= simple_form_for @advertisement, :html => {:multipart => true} do |f| %> <%= f.input :file, :as => :file %> - <%= f.input :referral_url %> - <%= f.input :ad_type, :collection => %w(vertical horizontal) %> + <%= f.input :referral_url, :as => :string %> <%= f.input :status, :collection => %w(active inactive) %> - <%= f.button :submit %> + <%= f.button :submit, "Submit" %> <% end %> \ No newline at end of file diff --git a/app/views/advertisements/_secondary_links.html.erb b/app/views/advertisements/_secondary_links.html.erb index ed08270f0..ef17422d7 100644 --- a/app/views/advertisements/_secondary_links.html.erb +++ b/app/views/advertisements/_secondary_links.html.erb @@ -1,4 +1,4 @@ -<% content_for(:secondary_nav_links) do %> +<% content_for(:secondary_links) do %>
  • <%= link_to "Listing", advertisements_path %>
  • <%= link_to "New", new_advertisement_path %>