Skip to content

Create group function#7

Merged
Motohide merged 9 commits intomasterfrom
create-group-function
Oct 20, 2017
Merged

Create group function#7
Motohide merged 9 commits intomasterfrom
create-group-function

Conversation

@Motohide
Copy link
Copy Markdown
Owner

#WHAT
グループ作成機能の実装
#WHY
必須機能のため

岩永規秀 added 4 commits October 18, 2017 20:11
マイグレーションファイルを作成。モデルでアソシエーションを定義。
必要のないファイルを削除。
ルーティングを定義。またコントローラーにnewアクションとcreateアクションを定義。
ビューの編集

private
def group_params
params.require(:group).permit(:name, users_id: [])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おそらく一人のuserしか登録できていないはずですので、複数のuserをgroupに登録できるようにしましょう!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

@@ -0,0 +1,5 @@
class AddNameTogroups < ActiveRecord::Migration[5.0]
def change
add_column :users, :group_id, :integer
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

制約をかけましょう!

@@ -0,0 +1,5 @@
class AddNameToGroups < ActiveRecord::Migration[5.0]
def change
add_column :groups, :name, :string
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

制約をかけましょう!

@@ -0,0 +1,6 @@
class AddUserIdToMembers < ActiveRecord::Migration[5.0]
def change
add_column :members, :user_id, :integer
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

制約をかけましょう!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

class AddUserIdToMembers < ActiveRecord::Migration[5.0]
def change
add_column :members, :user_id, :integer
add_column :members, :group_id, :integer
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

岩永規秀 added 3 commits October 19, 2017 11:50
マイグレーションファイルに制約を定義。
グループ作成機能において、複数のユーザーが登録できるようにした。

private
def group_params
params.require(:group).permit(:name, user_ids: [])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで複数user登録できていますか??

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実際にこの記述で試して見たんですけどこの記述で登録できてます!
書き方が悪いのでしょうか。

@@ -0,0 +1,5 @@
class AddNameTogroups < ActiveRecord::Migration[5.0]
def change
add_column :users, :group_id, :integer,null:false, unique: true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一意性制約ではなく外部キー制約をかけてください。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました。

create_table :members do |t|
t.references :user, foreign_key: true, null: false
t.references :group, foreign_key: true, null: false
t.integer :user_id
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenceで指定するのならこちらは不要です。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

t.references :user, foreign_key: true, null: false
t.references :group, foreign_key: true, null: false
t.integer :user_id
t.integer :group_id
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

岩永規秀 added 2 commits October 19, 2017 13:01
マイグレーションファイルを編集。
細かなビューなどを編集
@Motohide Motohide merged commit c1fd894 into master Oct 20, 2017
@Motohide Motohide deleted the create-group-function branch October 20, 2017 04:22
@Motohide Motohide restored the create-group-function branch October 20, 2017 06:16
@Motohide Motohide deleted the create-group-function branch October 20, 2017 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants