Permalink
Browse files

Added Ownership for Internships

Added the field to the db and added the logic to the controller to make the default owner the current user.
  • Loading branch information...
1 parent 5ee0a7c commit d2a527c658e0e6e247556f236908f77dfc3de939 @kcalmes kcalmes committed Nov 18, 2011
@@ -155,7 +155,9 @@ def show
# GET /internships/new.xml
def new
@internship = Internship.new
-
+
+ @internship.user = @current_user if @internship.user == nil
+
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @internship }
@@ -171,6 +173,7 @@ def edit
# POST /internships.xml
def create
@internship = Internship.new(params[:internship])
+
respond_to do |format|
if @internship.save
format.html { redirect_to(@internship, :notice => 'Internship was successfully created.') }
View
@@ -10,6 +10,8 @@ class Internship < ActiveRecord::Base
belongs_to :provider_contact
has_many :internship_instances
+ belongs_to :user
+
validates_presence_of :name
validates_presence_of :description
validates_presence_of :qualifications
@@ -44,7 +46,6 @@ def set_languages=(ids)
def set_locations=(ids)
self.location_ids = ids.split(",")
end
-
end
# == Schema Information
View
@@ -3,6 +3,8 @@ class User < ActiveRecord::Base
has_and_belongs_to_many :roles
has_and_belongs_to_many :tasks
+ has_many :internships
+
attr_accessor :display_name
def has_role roles
@@ -121,7 +121,7 @@
<%# link_to "Cancel", internships_path %>
</div>
- <%= theme_box(8, "Basic Information") do %>
+ <%= theme_box(8, "Basic Information") do %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
@@ -135,8 +135,8 @@
</div>
<div class="input_group">
<%= f.check_box :is_paid %>Paid?<br />
- <%= f.check_box :is_full_time %>Full-time?<br />
- <%= f.check_box :is_part_time %>Part-time?
+ <%= f.check_box :is_full_time %>Full-time?<br />
+ <%= f.check_box :is_part_time %>Part-time?
</div>
<div class="field">
@@ -232,6 +232,20 @@
<%= f.text_area :notes, :class => 'tiny_editor' %>
</div>
<% end %>
+ <%= theme_box(8, "Ownership", true) do %>
+ <% if can? :manage, :users %>
+ <div class="field">
+ <label>Net Id</label>
+ <div class="input_group">
+ <%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @internship.user.id} %>
+ </div>
+ <img class="add_img select" model="providers">
+ </div>
+ <% else %>
+ <%= f.hidden_field :user_id %>
+ <% end %>
+ <% end %>
+
<% end %>
<script>
$(function(){
@@ -0,0 +1,11 @@
+class AddUserIdToInternships < ActiveRecord::Migration
+ def self.up
+ add_column :internships, :user_id, :integer
+ dave = User.find_by_net_id('dlw34');
+ Internship.all.each { |f| f.update_attributes!(:user => dave) }
+ end
+
+ def self.down
+ remove_column :internships, :user_id
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111030163306) do
+ActiveRecord::Schema.define(:version => 20111104185219) do
create_table "academic_contacts", :force => true do |t|
t.string "name"
@@ -139,6 +139,7 @@
t.text "notes"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "user_id"
end
create_table "internships_languages", :id => false, :force => true do |t|
@@ -235,6 +236,7 @@
t.integer "tag_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "user_id"
end
create_table "states", :force => true do |t|

0 comments on commit d2a527c

Please sign in to comment.