-
Notifications
You must be signed in to change notification settings - Fork 1
Dev to master Homework#15 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SerafimD
wants to merge
18
commits into
master
Choose a base branch
from
dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6170007
Тип пользователя при создании аккаунта
KateGL 77b5777
Разделение на сообщества и людей : начало
KateGL e3f5fa3
Разделение на сообщества и людей : 2
KateGL 324375e
Исправление ошибки со связью community_membership при удалении User
KateGL 154a5de
контроллеры для people и community пока без тестов. Исправлена ошибка…
KateGL 7c526cb
редактирование и отображение данных для Person
KateGL 3625ad3
редактирование и отображение данных для Community
KateGL 4509f67
Тесты для users, пока не понимаю почему не создается нормально User д…
KateGL 33251b7
Тесты для users правильные. Убрала paginate из gemfile, вдруг он урон…
KateGL f52e329
Тесты для Person и Community
KateGL 736b74a
контроллеры, вью и тесты для CommunityMemberships
KateGL fab1f95
Тесты для community_membership, контроллеры, вью и тесты для UserRela…
KateGL 41e08b9
все для Post
KateGL d917bee
Рефаторинг по замечаниям к пул-реквесту
KateGL a3504c7
Merge pull request #17 from SerafimD/dev_new
SerafimD f7c23e3
Мёрдж двух основных веток.
SerafimD 55a13a0
bug fix for people_controller
SerafimD 3aba2f9
update README
SerafimD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 CommunitiesController < ApplicationController | ||
| before_action :find_current_community, only: [:show, :edit, :update] | ||
| before_filter :authenticate_user! | ||
|
|
||
| def index | ||
| @communities = Community.all | ||
| end | ||
|
|
||
| def show | ||
|
|
||
| end | ||
|
|
||
| def edit | ||
| render :new unless @community | ||
| end | ||
|
|
||
|
|
||
| def update | ||
| if @community.update(community_params) | ||
| render :show | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
|
|
||
| def new | ||
| @community = Community.new | ||
| end | ||
|
|
||
| def create | ||
| @community = Community.new(community_params) | ||
| @community.user_id = current_user.id | ||
| if @community.save | ||
| render :show | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
|
|
||
| private | ||
|
|
||
|
|
||
| def community_params | ||
| params.require(:community).permit(:subject) | ||
| end | ||
|
|
||
|
|
||
| def find_current_community | ||
| @community = Community.where(id: params[:id]).take | ||
| end | ||
| end |
This file contains hidden or 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,45 @@ | ||
| class CommunityMembershipsController < ApplicationController | ||
| before_action :find_current_community_membership, only: [:show, :destroy] | ||
| before_filter :authenticate_user! | ||
|
|
||
| def index | ||
|
|
||
| end | ||
|
|
||
| def show | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def new | ||
| @community_membership = CommunityMembership.new | ||
| end | ||
|
|
||
| def create | ||
| @community_membership = CommunityMembership.new(community_params) | ||
| @community_membership.community_id = current_user.id | ||
| if @community_membership.save | ||
| render :show | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| community_id = @community_membership.community_id | ||
| @community_membership.destroy | ||
| redirect_to url_for(:controller => :communities, :action => :show, :id => community_id) | ||
| end | ||
|
|
||
| private | ||
|
|
||
|
|
||
| def community_membership_params | ||
| params.require(:community_membership).permit(:user_id) | ||
| end | ||
|
|
||
|
|
||
| def find_current_community_membership | ||
| @community_membership = CommunityMembership.where(id: params[:id]).take | ||
| end | ||
| end |
This file contains hidden or 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,27 @@ | ||
| class MessagesController < ApplicationController | ||
|
|
||
| before_action :authenticate_user! | ||
|
|
||
| def index | ||
| @message_recieve = [] | ||
| @message_send = [] | ||
| current_user.recieved_messages.each {|t| @message_recieve << [User.find(t.user_id_to).name, t.message_text] } | ||
| current_user.send_messages.each {|t| @message_send << [User.find(t.user_id_from).name, t.message_text] } | ||
|
|
||
|
|
||
| @users = User.all | ||
|
|
||
| if request.method == "POST" | ||
| mes = Message.new | ||
| mes.message_text = params[:message] | ||
| current_user.send_messages << mes | ||
| User.find((params[:recive_id])).recieved_messages << mes | ||
| @test = params[:recive_id] | ||
| mes.save | ||
| redirect_to :action => :index | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| end |
This file contains hidden or 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,52 @@ | ||
| class PeopleController < ApplicationController | ||
| before_action :find_current_person, only: [:show, :edit, :update] | ||
| before_filter :authenticate_user! | ||
|
|
||
| def index | ||
| @people = Person.all | ||
| end | ||
|
|
||
| def show | ||
|
|
||
| end | ||
|
|
||
| def edit | ||
| render :new unless @person | ||
| end | ||
|
|
||
| def update | ||
| if @person.update(person_params) | ||
| render :show | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| def new | ||
| @person = Person.new | ||
| end | ||
|
|
||
| def create | ||
| @person = Person.new(person_params) | ||
| @person.user_id = current_user.id | ||
| if @person.save | ||
| redirect_to url_for(:controller => :people, :action => :show, :id => @person.id) | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
|
|
||
| private | ||
|
|
||
|
|
||
| def person_params | ||
| params.require(:person).permit(:surename, :date_of_birth) | ||
| end | ||
|
|
||
| def find_current_person | ||
| @person = Person.where(id: params[:id]).take | ||
| end | ||
|
|
||
|
|
||
| end |
This file contains hidden or 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,55 @@ | ||
| class PostsController < ApplicationController | ||
| before_action :find_current_post, only: [:show, :edit, :update, :destroy] | ||
| before_filter :authenticate_user! | ||
|
|
||
| def index | ||
|
|
||
| end | ||
|
|
||
| def show | ||
|
|
||
| end | ||
|
|
||
| def edit | ||
| render :new unless @post | ||
| end | ||
|
|
||
| def update | ||
| if @post.update(post_params) | ||
| render :show | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| def new | ||
| @post = Post.new | ||
| end | ||
|
|
||
| def create | ||
| @post = Post.new(post_params) | ||
| @post.user_id = current_user.id | ||
| if @post.save | ||
| render :show | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| @post.destroy | ||
| redirect_to user_root_path | ||
| end | ||
|
|
||
| private | ||
|
|
||
|
|
||
| def post_params | ||
| params.require(:post).permit(:content, :publish_date) | ||
| end | ||
|
|
||
| def find_current_post | ||
| @post = Post.where(id: params[:id]).take | ||
| end | ||
|
|
||
| end |
This file contains hidden or 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,45 @@ | ||
| class UserRelationsController < ApplicationController | ||
| before_action :find_current_user_relation, only: [:show, :destroy] | ||
| before_filter :authenticate_user! | ||
|
|
||
| def index | ||
|
|
||
| end | ||
|
|
||
| def show | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def new | ||
| @user_relation = UserRelation.new | ||
| end | ||
|
|
||
| def create | ||
| @user_relation = CommunityMembership.new(user_relation_params) | ||
| @user_relation.user_owner_id = current_user.id | ||
| if @user_relation.save | ||
| rednder :show | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| @user_relation.destroy | ||
| redirect_to user_root_path | ||
| end | ||
|
|
||
| private | ||
|
|
||
|
|
||
| def user_relation_params | ||
| params.require(:community_membership).permit(:user_rel_id) | ||
| end | ||
|
|
||
|
|
||
| def find_current_user_relation | ||
| @user_relation = UserRelation.where(id: params[:id]).take | ||
| end | ||
|
|
||
| end |
This file contains hidden or 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,40 @@ | ||
| class UsersController < ApplicationController | ||
|
|
||
| def profile | ||
| end | ||
| end | ||
|
|
||
| def show_profile | ||
| if current_user == nil | ||
| redirect_to new_user_session_path | ||
| return | ||
| end | ||
|
|
||
| user = User.where(id: current_user.id).take | ||
| if user == nil | ||
| redirect_to root_path | ||
| return | ||
| end | ||
|
|
||
| if user.person? | ||
| person = Person.where(user_id: user.id).take | ||
| if person == nil | ||
| redirect_to url_for(:controller => :people, :action => :new) | ||
| else | ||
| redirect_to url_for(:controller => :people, :action => :show, :id => person.id) | ||
| end | ||
|
|
||
| elsif user.community? | ||
| community = Community.where(user_id: user.id).take | ||
| if community == nil | ||
| redirect_to url_for(:controller => :communities, :action => :new) | ||
| else | ||
| redirect_to url_for(:controller => :communities, :action => :show, :id =>community.id) | ||
| end | ||
| else | ||
| redirect_to root_path | ||
| end | ||
|
|
||
|
|
||
| end | ||
|
|
||
| end | ||
This file contains hidden or 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,5 @@ | ||
| class WelcomeController < ApplicationController | ||
| def index | ||
|
|
||
| end | ||
| end |
This file contains hidden or 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,9 @@ | ||
| class Community < ActiveRecord::Base | ||
| has_one :user, :foreign_key => "id" | ||
| has_many :users, through: :community_memberships, dependent: :destroy | ||
| belongs_to :user, :foreign_key => "user_id" | ||
| has_many :users, through: :community_memberships#, dependent: :destroy | ||
| has_many :community_memberships, dependent: :destroy | ||
|
|
||
| def user | ||
| User.where(id: self.user_id).take | ||
| end | ||
| end |
This file contains hidden or 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,12 @@ | ||
| class CommunityMembership < ActiveRecord::Base | ||
| belongs_to :user | ||
| belongs_to :community | ||
| belongs_to :user, :foreign_key => "user_id" | ||
| belongs_to :community, :foreign_key => "community_id" | ||
|
|
||
| def user | ||
| User.where(id: self.user_id).take | ||
| end | ||
|
|
||
| def community | ||
| Community.where(id: self.community_id).take | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Замечания отписал в #13