1
0
Fork 0

Merge branch 'feature-course_sections'

This commit is contained in:
Andrew Tomaka 2013-04-12 13:19:24 -04:00
commit 897e39f64d
6 changed files with 36 additions and 10 deletions

View File

@ -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

View File

@ -1,4 +1,7 @@
<%= form_for @alert, :html => { :class => 'form-horizontal' } do |f| %>
<% if @alert.errors.any? %>
<%= @alert.errors.full_messages.join(',') %>
<% end %>
<div class="control-group">
<%= f.label :department, :class => 'control-label' %>
<div class="controls">
@ -11,6 +14,18 @@
<%= f.text_field :course, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :sections, :class => 'control-label' %>
<div class="controls">
<% 3.times do |key| %>
<%= text_field_tag(
'alert[sections][]',
params[:section] ? params[:section][key] : @alert.sections[key],
:class => 'text_field, span1'
) %>
<% end %>
</div>
</div>
<div class="control-group">
<%= f.label :semester, :class => 'control-label' %>
<div class="controls">

View File

@ -9,6 +9,7 @@
<th><%= model_class.human_attribute_name(:user_id) %></th>
<th><%= model_class.human_attribute_name(:department) %></th>
<th><%= model_class.human_attribute_name(:course) %></th>
<th><%= model_class.human_attribute_name(:sections) %></th>
<th><%= model_class.human_attribute_name(:semester) %></th>
<th><%= model_class.human_attribute_name(:alerted) %></th>
<th><%= model_class.human_attribute_name(:created_at) %></th>
@ -22,6 +23,7 @@
<td><%= alert.user_id %></td>
<td><%= alert.department %></td>
<td><%= alert.course %></td>
<td><%= alert.sections.join(', ') %></td>
<td><%= alert.semester %></td>
<td><%= alert.alerted %></td>
<td><%=l alert.created_at %></td>

View File

@ -10,6 +10,8 @@
<dd><%= @alert.department %></dd>
<dt><strong><%= model_class.human_attribute_name(:course) %>:</strong></dt>
<dd><%= @alert.course %></dd>
<dt><strong><%= model_class.human_attribute_name(:sections) %>:</strong></dt>
<dd><%= @alert.sections.join(', ') %>&nbsp;</dd>
<dt><strong><%= model_class.human_attribute_name(:semester) %>:</strong></dt>
<dd><%= @alert.semester %></dd>
<dt><strong><%= model_class.human_attribute_name(:alerted) %>:</strong></dt>

View File

@ -0,0 +1,5 @@
class AddSectionsToAlerts < ActiveRecord::Migration
def change
add_column :alerts, :sections, :text
end
end

View File

@ -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