Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added ownership to short term and long term goals

Did the same thing I did for internship for long term and short term goals.
  • Loading branch information...
commit 8cd89eb9e63fb0cc18c021034eff9c78f77321d7 1 parent 17e0228
kcalmes authored November 17, 2011
2  app/controllers/long_term_goals_controller.rb
@@ -33,6 +33,8 @@ def show
33 33
   def new
34 34
     @long_term_goal = LongTermGoal.new
35 35
 
  36
+    @long_term_goal.user = @current_user if @long_term_goal.user == nil
  37
+
36 38
     respond_to do |format|
37 39
       format.html # new.html.erb
38 40
       format.xml  { render :xml => @long_term_goal }
2  app/controllers/short_term_goals_controller.rb
@@ -56,6 +56,8 @@ def show
56 56
   # GET /short_term_goals/new.xml
57 57
   def new
58 58
     @short_term_goal = ShortTermGoal.new
  59
+    
  60
+    @short_term_goal.user = @current_user if @short_term_goal.user == nil
59 61
 
60 62
     respond_to do |format|
61 63
       format.html # new.html.erb
1  app/models/long_term_goal.rb
... ...
@@ -1,3 +1,4 @@
1 1
 class LongTermGoal < ActiveRecord::Base
2 2
   has_and_belongs_to_many :short_term_goals
  3
+  belongs_to :user
3 4
 end
1  app/models/short_term_goal.rb
@@ -2,6 +2,7 @@ class ShortTermGoal < ActiveRecord::Base
2 2
   has_and_belongs_to_many :long_term_goals
3 3
   has_many :tasks
4 4
   belongs_to :tag
  5
+  belongs_to :user
5 6
   
6 7
   # TOKEN PROCESSING FOR AUTO-COMPLETE
7 8
   def set_long_term_goals=(ids)
2  app/models/user.rb
@@ -4,6 +4,8 @@ class User < ActiveRecord::Base
4 4
   has_and_belongs_to_many :tasks
5 5
   
6 6
   has_many :internships
  7
+  has_many :short_term_goals
  8
+  has_many :long_term_goals
7 9
   
8 10
   attr_accessor :display_name
9 11
   
1  app/views/internships/_form.html.erb
@@ -239,7 +239,6 @@
239 239
 				<div class="input_group">
240 240
 					<%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @internship.user.id} %>
241 241
 				</div>
242  
-				<img class="add_img select" model="providers">
243 242
 			</div>
244 243
 		<% else %>
245 244
 			<%= f.hidden_field :user_id %>
12  app/views/long_term_goals/_form.html.erb
@@ -27,5 +27,17 @@
27 27
 		    <%= f.text_area :description %>
28 28
 		  </div>
29 29
 	<% end %>
  30
+	<%= theme_box(8, "Ownership", true) do %>	
  31
+		<% if can? :manage, :users %>
  32
+			<div class="field">
  33
+				<label>Net Id</label>
  34
+				<div class="input_group">
  35
+					<%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @long_term_goal.user.id} %>
  36
+				</div>
  37
+			</div>
  38
+		<% else %>
  39
+			<%= f.hidden_field :user_id %>
  40
+		<% end %>
  41
+	<% end %>
30 42
 	
31 43
 <% end %>
10  app/views/short_term_goals/_form.html.erb
@@ -124,6 +124,16 @@
124 124
 		<%= f.label :tag_id %><br />
125 125
 		<%= f.collection_select :tag_id, Tag.order(:name), :id, :name %>
126 126
 	</div>
  127
+	<% if can? :manage, :users %>
  128
+		<div class="field">
  129
+			<label>Net Id</label>
  130
+			<div class="input_group">
  131
+				<%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @short_term_goal.user.id} %>
  132
+			</div>
  133
+		</div>
  134
+	<% else %>
  135
+		<%= f.hidden_field :user_id %>
  136
+	<% end %>
127 137
   </div>
128 138
 	<% content_tag :button, :type => :submit, :class => "green round_all" do %>
129 139
  		<%= image_tag "icons/small/white/Bended%20Arrow%20Right.png" %>
11  db/migrate/20111104184544_add_user_id_to_short_term_goals.rb
... ...
@@ -0,0 +1,11 @@
  1
+class AddUserIdToShortTermGoals < ActiveRecord::Migration
  2
+  def self.up
  3
+    add_column :short_term_goals, :user_id, :integer
  4
+    dave = User.find_by_net_id('dlw34');
  5
+    ShortTermGoal.all.each { |f| f.update_attributes!(:user => dave) }
  6
+  end
  7
+
  8
+  def self.down
  9
+    remove_column :short_term_goals, :user_id
  10
+  end
  11
+end
11  db/migrate/20111118053112_add_user_id_to_long_term_goals.rb
... ...
@@ -0,0 +1,11 @@
  1
+class AddUserIdToLongTermGoals < ActiveRecord::Migration
  2
+  def self.up
  3
+    add_column :long_term_goals, :user_id, :integer
  4
+    dave = User.find_by_net_id('dlw34');
  5
+    LongTermGoal.all.each { |f| f.update_attributes!(:user => dave) }
  6
+  end
  7
+
  8
+  def self.down
  9
+    remove_column :long_term_goals, :user_id
  10
+  end
  11
+end

0 notes on commit 8cd89eb

Please sign in to comment.
Something went wrong with that request. Please try again.