例として StackOverflow を使用します。Question
私がモデルを持っているとしましょう。Question
ログインしたユーザーは、お気に入りの 1 つとして「スター」を付けることができます。データベースでは、この種のものはおそらくフィールドとフィールドを持つUserQuestions
テーブルに格納されます。実際には「リスト」、「追加」、「削除」しかないため、この種の機能は典型的な CRUD ではありません。また、「ユーザーのスター付き質問」リストに表示されるレコードは、レコードではなく、レコードである必要があります。コントローラーとモデルに入れるコードは何ですか?user_id
question_id
UserQuestion
Question
UserQuestion
class MyFavoriteQuestionsController < ApplicationController
def index
#list just the questions associated with current_user
end
def add
#insert a row in the database for current_user and selected question
def
def remove
#remove the row from the database
end
end