Conversation
added 4 commits
October 18, 2017 20:11
マイグレーションファイルを作成。モデルでアソシエーションを定義。
必要のないファイルを削除。
ルーティングを定義。またコントローラーにnewアクションとcreateアクションを定義。
TOMARUMARU
reviewed
Oct 18, 2017
app/controllers/groups_controller.rb
Outdated
|
|
||
| private | ||
| def group_params | ||
| params.require(:group).permit(:name, users_id: []) |
There was a problem hiding this comment.
おそらく一人のuserしか登録できていないはずですので、複数のuserをgroupに登録できるようにしましょう!
| @@ -0,0 +1,5 @@ | |||
| class AddNameTogroups < ActiveRecord::Migration[5.0] | |||
| def change | |||
| add_column :users, :group_id, :integer | |||
| @@ -0,0 +1,5 @@ | |||
| class AddNameToGroups < ActiveRecord::Migration[5.0] | |||
| def change | |||
| add_column :groups, :name, :string | |||
| @@ -0,0 +1,6 @@ | |||
| class AddUserIdToMembers < ActiveRecord::Migration[5.0] | |||
| def change | |||
| add_column :members, :user_id, :integer | |||
| class AddUserIdToMembers < ActiveRecord::Migration[5.0] | ||
| def change | ||
| add_column :members, :user_id, :integer | ||
| add_column :members, :group_id, :integer |
added 3 commits
October 19, 2017 11:50
マイグレーションファイルに制約を定義。
TOMARUMARU
reviewed
Oct 19, 2017
|
|
||
| private | ||
| def group_params | ||
| params.require(:group).permit(:name, user_ids: []) |
Owner
Author
There was a problem hiding this comment.
実際にこの記述で試して見たんですけどこの記述で登録できてます!
書き方が悪いのでしょうか。
| @@ -0,0 +1,5 @@ | |||
| class AddNameTogroups < ActiveRecord::Migration[5.0] | |||
| def change | |||
| add_column :users, :group_id, :integer,null:false, unique: true | |||
| 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 |
| t.references :user, foreign_key: true, null: false | ||
| t.references :group, foreign_key: true, null: false | ||
| t.integer :user_id | ||
| t.integer :group_id |
added 2 commits
October 19, 2017 13:01
マイグレーションファイルを編集。
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#WHAT
グループ作成機能の実装
#WHY
必須機能のため