-
Notifications
You must be signed in to change notification settings - Fork 74
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
Q&Aで、メンターと管理者が「質問作成者」を変更できるようにする #7817
base: main
Are you sure you want to change the base?
Q&Aで、メンターと管理者が「質問作成者」を変更できるようにする #7817
Conversation
@machida
|
@nishitatsu-dev お待たせしました!デザイン調整を行いました。 |
@machida |
3e09c8e
to
8a2ef77
Compare
変更箇所の補足メモ変更の意図が分かりにくい部分についてのメモです
|
@nakamu-kazu222 |
@nakamu-kazu222 |
@masyuko0222 変更箇所に関する補足メモです→ #7817 (comment) |
@nishitatsu-dev |
@masyuko0222 |
申し訳ございません 次の機会がありましたら、よろしくお願いいたします |
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.
動作確認大丈夫でした!
気になる点をコメントしましたので、ご確認よろしくお願いいたします。
app/views/questions/_form.html.slim
Outdated
= f.label :user_id, '作成者', class: 'a-form-label' | ||
.select-user | ||
- if question.new_record? | ||
= f.collection_select(:user_id, User.order(:login_name), :id, :login_name, { selected: current_user }, |
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.
初期値としてcurrent_userを選択しておくことを期待されているのかと思いますが、今はなっていません。
selected
オプションにはUserオブジェクトではなく、Userのidを渡すべきかと思います。
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.
ありがとうございます。チェックしたつもりになっていました🙏
idを渡すように修正しました〜
(動作も確認しました〜)
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.
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.
色々とチェックありがとうございます!!勉強になります🙏
- 原因:以下2つのバリデーションが実行されていました〜
belongs_to :user
belongs_to
は、バリデーションを実行するのがデフォルトで、optional: true
を付けると実行されないそうです。参考:Active Record の関連付け 4.1.2.11 :optional - Railsガイド v6.1。(ご存知でしたらすみません🙇🏻)validates :user, presence: true
- 対応:ⅱの方を削除しました〜
8a2ef77
to
c3fd234
Compare
@masyuko0222 |
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.
確認できました!OKです!
@masyuko0222 |
@komagata |
@@ -52,7 +52,8 @@ def new | |||
def edit; end | |||
|
|||
def create | |||
@question = current_user.questions.new(question_params) | |||
@question = Question.new(question_params) | |||
@question.user = current_user unless admin_login? || current_user.mentor? |
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.
@question.user = current_user unless admin_login? || current_user.mentor? | |
@question.user = current_user if !admin_or_mentor_login? |
unlessとorが両方あると理解しずらいので避けるのがいいと思います。
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.
ありがとうございます🙏提案いただいた書き方に修正しました。
また、app/views/questions/_form.html.slim
の、「フォーム表示に関する条件分岐(55行目)」も同じメソッドを使うように修正しました。
c3fd234
to
624f219
Compare
@komagata |
@nishitatsu-dev マージコミットが入っているようなので修正してみてください~ |
途中保存(Choices.jsを使った表示) 途中保存(既存テスト確認中) 途中保存(既存テストOK) 途中保存(テスト作りかけ) Q&Aでmentorとadminが質問者を変更できる(初版)
624f219
to
4fe16ef
Compare
@komagata |
Issue
概要
(メンターと管理者だけの機能。他のユーザーには表示されない)
変更確認方法
feature/questioner-can-be-changed-by-mentor-or-admin
をローカルに取り込む(
http://localhost:3000/questions?target=not_solved
)」にアクセスする+ 質問する
ボタン」または「既存の質問」をクリックし、編集画面に移動する(新規作成の場合は、「タイトル」と「質問文」の入力が必要)
登録する
:新規作成の場合質問を公開
:WIP
ボタンで途中保存した質問の場合更新する
:既に公開されている質問を編集した場合Screenshot
変更前(質問の編集画面)
変更後(質問の編集画面)