Skip to content
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

1_table_set #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

1_table_set #1

wants to merge 4 commits into from

Conversation

hirohiroiida
Copy link
Owner

検索機能と管理者機能がこのテーブルでできるのか、定かではないのですが、1度チェックお願いします!

Copy link

@DaichiSaito DaichiSaito left a comment

Choose a reason for hiding this comment

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

コメントしましたー。
ファイルの拡張子は.mdの方が良いですよ。マークダウンが使えるので。

また、

* users
   ・nickname:string

じゃなく

* users
  * nickname: string

にしましょう。

何がどう違うのかは考えてみてください。

table_set.txt Outdated
@@ -0,0 +1,34 @@
* users
・nickname:string
・avatar_image_id:string

Choose a reason for hiding this comment

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

これは何でしょう?

Copy link
Owner Author

Choose a reason for hiding this comment

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

以前作ったrailsのアプリで画像の登録を実像する際、gemのgem "refile" と "refile-mini_magick"を使ったことがあるのですが、そのときにimage_id: string のような書き方で実装できたいたので、このような書き方をしました。

Choose a reason for hiding this comment

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

なるほどー。これはActiveStorageを使った方が楽だと思いますよ。

ちなみに課題図書の現場で使えるRuby on Rails 5速習実践ガイドって読みました?

https://tech-essentials.work/courses/7

課題内容
Rubyのフレームワークである『Rails』の基本から応用までを学びましょう。
書籍『現場で使える Ruby on Rails 5速習実践ガイド』を読み、学んだことをアウトプットしてください。
現場で使える Ruby on Rails 5速習実践ガイド

Copy link
Owner Author

Choose a reason for hiding this comment

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

すいません。まだ購入してなかったので、月曜日届いたら読みます。
そして、届いたのですが、結構時間がかかるので、やりながらこちらも取り組んでいきます!

table_set.txt Outdated
・avatar_image_id:string
・email:string
・password:string
・hostman:boolean

Choose a reason for hiding this comment

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

これはなんでしょう

Copy link
Owner Author

Choose a reason for hiding this comment

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

管理者か一般ユーザーを見分けるためのカラムにするつもりでした。
デフォルト値を設定して、一般ユーザーはいじれないようにしとけば管理者を判断できるかなと思いました。

Choose a reason for hiding this comment

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

なるほど。hostmanという命名は聞いたことないのであまり一般的ではないと思います。adminでどうでしょうか?

Copy link
Owner Author

Choose a reason for hiding this comment

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

admin(管理者)に変えます!

table_set.txt Outdated
* questions
・user_id:integer
・title:string
・text:body

Choose a reason for hiding this comment

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

body:textですかね。

Copy link
Owner Author

Choose a reason for hiding this comment

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

以前作ったrailsのスキーマーを見ながら作っていたので、間違えました・・・
直します!

table_set.txt Outdated
* answers
・user_id:integer
・question_id:integer
・comment:body

Choose a reason for hiding this comment

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

comment:bodyとはなんでしょう?

Copy link
Owner Author

Choose a reason for hiding this comment

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

本当はanswerにしたかったのですが、テーブル名と被ると以前エラーでた記憶があってこのような書き方をしました。回答の中身を入れるカラムのつもりです。bodyは間違いです。。。

Choose a reason for hiding this comment

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

テーブル名と被ると以前エラーでた記憶があって

これは勘違いだと思います。
とはいえanswer.answerのように参照するのは違和感あるのでbodyカラムにしたほうが良いかと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

bodyに変えます。テーブル名勉強します。

table_set.txt Outdated
・created_at:datetime
・updated_at:datetime

* solutions

Choose a reason for hiding this comment

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

これは何のためのテーブルでしょう?

Copy link
Owner Author

Choose a reason for hiding this comment

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

解決したか、してないかを実装するテーブルのつもりでした。
いいね機能のテーブルがこんな感じだったので参考にしました。

Choose a reason for hiding this comment

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

いいね機能のテーブルがこんな感じだったので参考にしました。

どこをどう参考にしましたか?根拠を教えていただければなと思います!

Copy link
Owner Author

Choose a reason for hiding this comment

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

いいねのon,off と 解決した、解決していないボタン で2パターンの動きなので、近いかなーと思いました。
すいません。いいね機能も完全に理解して、実装したわけではなかったので、はっきり答えられません。

Choose a reason for hiding this comment

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

こういう理解が曖昧なところをメンターに質問してほしいなぁと思います。
どうしても課題を進めることが目的になっちゃってる感じがします。

質問してもらえれば考え方のヒントを答えるので理解が曖昧なところはそのままにしないで質問してほしいです...!

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます!質問します!

この解決したボタンについては、questions のテーブルに 解決したか、してないかを判断するカラムさえあればいい、と思いました。

table_set.txt Outdated

* solutions
・user_id:integer
・questions_id:integer

Choose a reason for hiding this comment

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

単数, 複数どちらが正しいでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

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

解決に数はないので単数です。

Choose a reason for hiding this comment

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

「rails テーブル名 ルール」とかで調べてみましょう。

Copy link
Owner Author

Choose a reason for hiding this comment

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

調べます。
モデル名は単数形、テーブル名は、スネークケースの複数形です。

Choose a reason for hiding this comment

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

もう修正されているので把握されていると思いますけど、ここでだいそんさんが質問しているのは「questions_id」のことだと思いますよ!

Copy link
Owner Author

Choose a reason for hiding this comment

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

全然気づいてませんでした。みけたさん、ありがとうございます!

questions_id ではなく question_id でした。
idは一つのquestion と紐付いてるので、s はいらなかったです。
あってますでしょうか!?><

Copy link

Choose a reason for hiding this comment

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

idは一つのquestion と紐付いてるので、s はいらなかったです。

確かにそれはそうなんですが、Railsのルールとして覚えておきましょう。
https://railsguides.jp/active_record_basics.html#%E5%91%BD%E5%90%8D%E3%83%AB%E3%83%BC%E3%83%AB
https://railsguides.jp/active_record_basics.html#%E3%82%B9%E3%82%AD%E3%83%BC%E3%83%9E%E3%81%AE%E3%83%AB%E3%83%BC%E3%83%AB

Copy link
Owner Author

Choose a reason for hiding this comment

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

はい!覚えます!

table_set.md Outdated
@@ -3,31 +3,45 @@
* avatar_image_id: string
* email: string
* password: string

Choose a reason for hiding this comment

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

テーブル設計とは関係ない部分ですが、セキュリティの観点から、実際に保存するのはパスワード自体でなく、パスワードを暗号化したものにするのが定石というのをおさえておくといいと思います!

https://qiita.com/ryosuketter/items/805452b7e6bf9637cb57
https://railstutorial.jp/chapters/modeling-users?version=4.0#sec-an_encrypted_password

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。抑えます!。。ちなみに、
gem devise を使うと、アクセストークンなどのpsに関わりそうなカラムができるのですが関係あるのでしょうか!?
アクセストークンっていうのは別の話ですか?

Choose a reason for hiding this comment

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

まず「アクセストークンとは」でググってみましょう 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

アクセストークンは別の話でした。。。

Copy link

@DaichiSaito DaichiSaito left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

None yet

3 participants