-
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 #12 from meyerhoferc/user-groups
User groups
- Loading branch information
Showing
27 changed files
with
343 additions
and
97 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 |
---|---|---|
@@ -1 +1 @@ | ||
2.3.0 | ||
2.3.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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
class ApplicationController < ActionController::Base | ||
helper_method :current_user | ||
helper_method :current_user, :authorized_user | ||
|
||
def current_user | ||
@current_user ||= User.find(session[:user_id]) if session[:user_id] | ||
end | ||
|
||
def authorized_user(other_user) | ||
current_user.id == other_user.id | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class DashboardController < ApplicationController | ||
def show | ||
if !current_user | ||
redirect_to root_path | ||
flash[:warning] = 'You must be logged in first.' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class GroupsController < ApplicationController | ||
before_action :set_group, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@groups = Group.all | ||
end | ||
|
||
def new | ||
@group = Group.new | ||
end | ||
|
||
def create | ||
@group = Group.new(group_params) | ||
@group.user_ids= current_user.id | ||
if @group.save | ||
redirect_to dashboard_path | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @group.update(group_params) | ||
flash[:notice] = "Group '#{@group.name}' updated!" | ||
redirect_to group_path(@group) | ||
else | ||
flash[:warning] = 'An error occurred, please try again.' | ||
render 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@group.destroy | ||
flash[:notice] = 'Group Deleted!' | ||
redirect_to dashboard_path | ||
end | ||
|
||
private | ||
|
||
def set_group | ||
@group = Group.find(params[:id]) | ||
end | ||
|
||
def group_params | ||
params.require(:group).permit(:name, :description) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class WelcomeController < ApplicationController | ||
def index | ||
if current_user | ||
redirect_to dashboard_path | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Group < ApplicationRecord | ||
has_many :user_groups | ||
has_many :users, through: :user_groups | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class UserGroup < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :group | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<% if current_user %> | ||
<h1><%= "Welcome, #{current_user.first_name || current_user.email}." %></h1> | ||
<%= link_to 'Profile', profile_path %> | ||
<%= link_to 'Sign Out', logout_path, method: :delete %> | ||
|
||
<h2>My Groups</h2> | ||
<%= link_to "Create a Group", new_group_path %> | ||
<br> | ||
<% if !current_user.groups.empty? %> | ||
<%= render partial: 'users/groups', collection: current_user.groups %> | ||
<% else %> | ||
You are not part of any groups. | ||
<% end %> | ||
<% end %> |
Oops, something went wrong.