-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from christinalcole/feature-position-mgmt
Feature position mgmt
- Loading branch information
Showing
10 changed files
with
145 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Users::PositionManagementController < ApplicationController | ||
# def edit | ||
# positions_users = current_user.positions_users | ||
# Position.find_each do |position| | ||
# unless positions_users.detect {|pu| pu.position_id == position.id} | ||
# current_user.positions_users.build(position_id: position.id)#, skill_level: 0) | ||
# end | ||
# end | ||
# end | ||
|
||
def edit | ||
@positions = Position.all | ||
@positions_users = current_user.positions_users | ||
end | ||
|
||
def update | ||
if current_user.update(user_position_params) | ||
redirect_to user_positions_path(current_user) | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
private | ||
def user_position_params | ||
params.require(:user).permit(:user, positions_users_attributes: [:position_id, :skill_level]) | ||
end | ||
end | ||
|
||
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"7ygP/H3za91bM2UrP5TbeyN1EAhbPYCCCnvml14Yur5MuWqMXhxLpdh0Np+SYHDAjV7IdeFJ61+tVZVjJ3QAqA==", "user"=>{"positions_users_attributes"=>{"0"=>{"position_id"=>"1", "skill_level"=>"4"}, "1"=>{"skill_level"=>""}}}, "commit"=>"Update User", "controller"=>"users", "action"=>"update", "id"=>"1"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<hr> | ||
user::position_management#edit | ||
|
||
|
||
<h2>Manage the positions on your profile:</h2> | ||
|
||
|
||
|
||
<hr></br> | ||
<%= form_for current_user, url: user_position_management_path do |f| %> | ||
<% @positions.each do |position| %> | ||
<%= f.fields_for :positions_users, PositionsUser.new do |pu_fields| %> | ||
<%= pu_fields.check_box :position_id, {checked: current_user.has_positions?(position), id: "position_#{position.id}"}, position.id, nil %> | ||
<%= pu_fields.label :name, position.name, for: "position_#{position.id}" %> | ||
<%= pu_fields.text_field :skill_level, value: current_user.has_positions?(position) ? current_user.skill_level(position) : '' %><br> | ||
<% end %> | ||
<% end %> | ||
<%= f.submit "Manage Position(s)" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20180320230510_remove_not_null_constraint_on_positions_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveNotNullConstraintOnPositionsUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
change_column_null :positions_users, :skill_level, true | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrate/20180320230855_add_timestamps_to_positions_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddTimestampsToPositionsUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_timestamps :positions_users, null: true | ||
|
||
long_ago = DateTime.new(2003, 8, 13) | ||
PositionsUser.update_all(created_at: long_ago, updated_at: long_ago) | ||
|
||
change_column_null :positions_users, :created_at, false | ||
change_column_null :positions_users, :updated_at, false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters