From fa9e9ff866025f3f558b18979790fc7f33d8a1dc Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 11 Apr 2013 21:30:02 -0400 Subject: [PATCH 1/6] Add sections column to alerts --- db/migrate/20130412012722_add_sections_to_alerts.rb | 5 +++++ db/schema.rb | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20130412012722_add_sections_to_alerts.rb diff --git a/db/migrate/20130412012722_add_sections_to_alerts.rb b/db/migrate/20130412012722_add_sections_to_alerts.rb new file mode 100644 index 0000000..b2c157c --- /dev/null +++ b/db/migrate/20130412012722_add_sections_to_alerts.rb @@ -0,0 +1,5 @@ +class AddSectionsToAlerts < ActiveRecord::Migration + def change + add_column :alerts, :sections, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 1eed245..5c80be9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130407102854) do +ActiveRecord::Schema.define(:version => 20130412012722) do create_table "alerts", :force => true do |t| t.integer "user_id" @@ -21,6 +21,7 @@ ActiveRecord::Schema.define(:version => 20130407102854) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "semester" + t.text "sections" end create_table "roles", :force => true do |t| @@ -34,6 +35,13 @@ ActiveRecord::Schema.define(:version => 20130407102854) do add_index "roles", ["name", "resource_type", "resource_id"], :name => "index_roles_on_name_and_resource_type_and_resource_id" add_index "roles", ["name"], :name => "index_roles_on_name" + create_table "sections", :force => true do |t| + t.integer "alert_id" + t.string "section" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "email", :default => "", :null => false t.string "encrypted_password", :default => "", :null => false From 8c05bfd52336b2ecef0788d1cfbd29f68fa34e56 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 11 Apr 2013 21:38:41 -0400 Subject: [PATCH 2/6] Setup sections in model --- app/models/alert.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/alert.rb b/app/models/alert.rb index eed0b1c..aff04bf 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -24,6 +24,9 @@ class Alert < ActiveRecord::Base # only_integer: true # } validates :semester, :presence => true + validates :sections, :presence => true + + serialize :sections scope :user_alerts, lambda { |user_id| where('Alerts.user_id = ?', user_id) From f79bb3eddcd70c6b7360679d8dd29e28147de262 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 12 Apr 2013 13:12:29 -0400 Subject: [PATCH 3/6] Update model to allow for serialized sections --- app/models/alert.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/models/alert.rb b/app/models/alert.rb index aff04bf..e88edd4 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -1,5 +1,5 @@ class Alert < ActiveRecord::Base - attr_accessible :course, :department, :semester + attr_accessible :course, :department, :semester, :sections attr_protected :user_id attr_protected :alerted @@ -19,14 +19,9 @@ class Alert < ActiveRecord::Base :format => { :with => /\A[0-9]+[A-Za-z]?\Z/ } - # validates :user_id, :presence => true, - # :numericality => { - # only_integer: true - # } validates :semester, :presence => true - validates :sections, :presence => true - serialize :sections + serialize :sections, Array scope :user_alerts, lambda { |user_id| where('Alerts.user_id = ?', user_id) @@ -39,8 +34,4 @@ class Alert < ActiveRecord::Base def course_name "#{self.department} #{self.course}" end - - def sections - - end end From c9fdc8677575a62c6a971d82231c4468964047c8 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 12 Apr 2013 13:13:42 -0400 Subject: [PATCH 4/6] Update show view to display sections --- app/views/alerts/show.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/alerts/show.html.erb b/app/views/alerts/show.html.erb index a77d25a..ad79a65 100644 --- a/app/views/alerts/show.html.erb +++ b/app/views/alerts/show.html.erb @@ -10,6 +10,8 @@
<%= @alert.department %>
<%= model_class.human_attribute_name(:course) %>:
<%= @alert.course %>
+
<%= model_class.human_attribute_name(:sections) %>:
+
<%= @alert.sections.join(', ') %> 
<%= model_class.human_attribute_name(:semester) %>:
<%= @alert.semester %>
<%= model_class.human_attribute_name(:alerted) %>:
From a4a6e58bab3d1881a66636c60a55be5cb7445eec Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 12 Apr 2013 13:14:52 -0400 Subject: [PATCH 5/6] Update index to list sections --- app/views/alerts/index.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/alerts/index.html.erb b/app/views/alerts/index.html.erb index 91bde26..3a91420 100644 --- a/app/views/alerts/index.html.erb +++ b/app/views/alerts/index.html.erb @@ -9,6 +9,7 @@ <%= model_class.human_attribute_name(:user_id) %> <%= model_class.human_attribute_name(:department) %> <%= model_class.human_attribute_name(:course) %> + <%= model_class.human_attribute_name(:sections) %> <%= model_class.human_attribute_name(:semester) %> <%= model_class.human_attribute_name(:alerted) %> <%= model_class.human_attribute_name(:created_at) %> @@ -22,6 +23,7 @@ <%= alert.user_id %> <%= alert.department %> <%= alert.course %> + <%= alert.sections.join(', ') %> <%= alert.semester %> <%= alert.alerted %> <%=l alert.created_at %> From ce21f00597f1ed93723d8eec12af84993fd294db Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 12 Apr 2013 13:18:31 -0400 Subject: [PATCH 6/6] Update form to accept sections --- app/views/alerts/_form.html.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/views/alerts/_form.html.erb b/app/views/alerts/_form.html.erb index 5937420..79d38f4 100644 --- a/app/views/alerts/_form.html.erb +++ b/app/views/alerts/_form.html.erb @@ -1,4 +1,7 @@ <%= form_for @alert, :html => { :class => 'form-horizontal' } do |f| %> + <% if @alert.errors.any? %> + <%= @alert.errors.full_messages.join(',') %> + <% end %>
<%= f.label :department, :class => 'control-label' %>
@@ -11,6 +14,18 @@ <%= f.text_field :course, :class => 'text_field' %>
+
+ <%= f.label :sections, :class => 'control-label' %> +
+ <% 3.times do |key| %> + <%= text_field_tag( + 'alert[sections][]', + params[:section] ? params[:section][key] : @alert.sections[key], + :class => 'text_field, span1' + ) %> + <% end %> +
+
<%= f.label :semester, :class => 'control-label' %>