diff --git a/app/models/alert.rb b/app/models/alert.rb index eed0b1c..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,12 +19,10 @@ 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 + serialize :sections, Array + scope :user_alerts, lambda { |user_id| where('Alerts.user_id = ?', user_id) } @@ -36,8 +34,4 @@ class Alert < ActiveRecord::Base def course_name "#{self.department} #{self.course}" end - - def sections - - end end 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' %>
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 %> 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) %>:
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